From 5915ca8d388ded617fd18a3929b36cb957b47a21 Mon Sep 17 00:00:00 2001 From: Stefan Hayden Date: Tue, 1 Nov 2016 06:11:01 -0400 Subject: [PATCH] Trigger mouse over on canvas enter (#3389) * fire a mouse:over event once when mouse enters the canvas * only fire if we don't find a target * only fire if we find no target and set the hoveredTarget to null --- src/mixins/canvas_events.mixin.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/mixins/canvas_events.mixin.js b/src/mixins/canvas_events.mixin.js index f5cfea08..2b78d521 100644 --- a/src/mixins/canvas_events.mixin.js +++ b/src/mixins/canvas_events.mixin.js @@ -44,6 +44,7 @@ addListener(this.upperCanvasEl, 'mousedown', this._onMouseDown); addListener(this.upperCanvasEl, 'mousemove', this._onMouseMove); addListener(this.upperCanvasEl, 'mouseout', this._onMouseOut); + addListener(this.upperCanvasEl, 'mouseenter', this._onMouseEnter); addListener(this.upperCanvasEl, 'wheel', this._onMouseWheel); addListener(this.upperCanvasEl, 'contextmenu', this._onContextMenu); @@ -75,6 +76,7 @@ this._onOrientationChange = this._onOrientationChange.bind(this); this._onMouseWheel = this._onMouseWheel.bind(this); this._onMouseOut = this._onMouseOut.bind(this); + this._onMouseEnter = this._onMouseEnter.bind(this); this._onContextMenu = this._onContextMenu.bind(this); }, @@ -87,6 +89,7 @@ removeListener(this.upperCanvasEl, 'mousedown', this._onMouseDown); removeListener(this.upperCanvasEl, 'mousemove', this._onMouseMove); removeListener(this.upperCanvasEl, 'mouseout', this._onMouseOut); + removeListener(this.upperCanvasEl, 'mouseenter', this._onMouseEnter); removeListener(this.upperCanvasEl, 'wheel', this._onMouseWheel); removeListener(this.upperCanvasEl, 'contextmenu', this._onContextMenu); @@ -139,6 +142,17 @@ target && target.fire('mouseout', { e: e }); }, + /** + * @private + * @param {Event} e Event object fired on mouseenter + */ + _onMouseEnter: function(e) { + if (!this.findTarget(e)) { + this.fire('mouse:over', { target: null, e: e }); + this._hoveredTarget = null; + } + }, + /** * @private * @param {Event} [e] Event object fired on Event.js orientation change