From 8debb26d617065dd4aad816b1ee582471ffdf0c1 Mon Sep 17 00:00:00 2001 From: Antoine Vandecreme Date: Tue, 22 Oct 2013 16:54:04 -0400 Subject: [PATCH 1/3] Add mouse stop event --- src/mousetracker.js | 51 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/mousetracker.js b/src/mousetracker.js index e0b9e931..8e19f34c 100644 --- a/src/mousetracker.js +++ b/src/mousetracker.js @@ -59,11 +59,14 @@ * A reference to an element or an element id for which the mouse * events will be monitored. * @param {Number} options.clickTimeThreshold - * The number of milliseconds within which mutliple mouse clicks + * The number of milliseconds within which multiple mouse clicks * will be treated as a single event. * @param {Number} options.clickDistThreshold * The distance between mouse click within multiple mouse clicks * will be treated as a single event. + * @param {Number} options.stopDelay + * The number of milliseconds without mouse move before the mouse stop + * event is fired. * @param {Function} options.enterHandler * An optional handler for mouse enter. * @param {Function} options.exitHandler @@ -116,6 +119,7 @@ this.clickTimeThreshold = options.clickTimeThreshold; this.clickDistThreshold = options.clickDistThreshold; this.userData = options.userData || null; + this.stopDelay = options.stopDelay || 50; this.enterHandler = options.enterHandler || null; this.exitHandler = options.exitHandler || null; @@ -125,6 +129,7 @@ this.scrollHandler = options.scrollHandler || null; this.clickHandler = options.clickHandler || null; this.dragHandler = options.dragHandler || null; + this.stopHandler = options.stopHandler || null; this.keyHandler = options.keyHandler || null; this.focusHandler = options.focusHandler || null; this.blurHandler = options.blurHandler || null; @@ -389,6 +394,24 @@ */ dragHandler: function () { }, + /** + * Implement or assign implementation to these handlers during or after + * calling the constructor. + * @function + * @param {Object} event + * @param {OpenSeadragon.MouseTracker} event.eventSource + * A reference to the tracker instance. + * @param {OpenSeadragon.Point} event.position + * The position of the event relative to the tracked element. + * @param {Boolean} event.isTouchEvent + * True if the original event is a touch event, otherwise false. + * @param {Object} event.originalEvent + * The original event object. + * @param {Object} event.userData + * Arbitrary user-defined object. + */ + stopHandler: function () { }, + /** * Implement or assign implmentation to these handlers during or after * calling the constructor. @@ -1053,8 +1076,34 @@ $.cancelEvent( event ); } } + if ( tracker.stopHandler ) { + clearTimeout( tracker.stopTimeOut ); + tracker.stopTimeOut = setTimeout( function() { + onMouseStop( tracker, event ); + }, tracker.stopDelay ); + } } + + /** + * @private + * @inner + */ + function onMouseStop( tracker, event ) { + if ( tracker.stopHandler ) { + event = $.getEvent( event ); + var propagate = tracker.stopHandler( { + eventSource: tracker, + position: getMouseRelative( event, tracker.element ), + isTouchEvent: false, + originalEvent: event, + userData: tracker.userData + } ); + if ( propagate === false ) { + $.cancelEvent( event ); + } + } + } /** * @private From 542d5f5aebe950641162a88f720718d89ed8d128 Mon Sep 17 00:00:00 2001 From: Antoine Vandecreme Date: Wed, 30 Oct 2013 21:28:10 -0400 Subject: [PATCH 2/3] Remove cancelEvent + fix typos --- src/mousetracker.js | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/mousetracker.js b/src/mousetracker.js index 8e19f34c..4ce7e82c 100644 --- a/src/mousetracker.js +++ b/src/mousetracker.js @@ -224,7 +224,7 @@ }, /** - * Implement or assign implmentation to these handlers during or after + * Implement or assign implementation to these handlers during or after * calling the constructor. * @function * @param {Object} event @@ -247,7 +247,7 @@ enterHandler: function () { }, /** - * Implement or assign implmentation to these handlers during or after + * Implement or assign implementation to these handlers during or after * calling the constructor. * @function * @param {Object} event @@ -270,7 +270,7 @@ exitHandler: function () { }, /** - * Implement or assign implmentation to these handlers during or after + * Implement or assign implementation to these handlers during or after * calling the constructor. * @function * @param {Object} event @@ -288,7 +288,7 @@ pressHandler: function () { }, /** - * Implement or assign implmentation to these handlers during or after + * Implement or assign implementation to these handlers during or after * calling the constructor. * @function * @param {Object} event @@ -311,7 +311,7 @@ releaseHandler: function () { }, /** - * Implement or assign implmentation to these handlers during or after + * Implement or assign implementation to these handlers during or after * calling the constructor. * @function * @param {Object} event @@ -329,7 +329,7 @@ moveHandler: function () { }, /** - * Implement or assign implmentation to these handlers during or after + * Implement or assign implementation to these handlers during or after * calling the constructor. * @function * @param {Object} event @@ -351,7 +351,7 @@ scrollHandler: function () { }, /** - * Implement or assign implmentation to these handlers during or after + * Implement or assign implementation to these handlers during or after * calling the constructor. * @function * @param {Object} event @@ -373,7 +373,7 @@ clickHandler: function () { }, /** - * Implement or assign implmentation to these handlers during or after + * Implement or assign implementation to these handlers during or after * calling the constructor. * @function * @param {Object} event @@ -413,7 +413,7 @@ stopHandler: function () { }, /** - * Implement or assign implmentation to these handlers during or after + * Implement or assign implementation to these handlers during or after * calling the constructor. * @function * @param {Object} event @@ -431,7 +431,7 @@ keyHandler: function () { }, /** - * Implement or assign implmentation to these handlers during or after + * Implement or assign implementation to these handlers during or after * calling the constructor. * @function * @param {Object} event @@ -445,7 +445,7 @@ focusHandler: function () { }, /** - * Implement or assign implmentation to these handlers during or after + * Implement or assign implementation to these handlers during or after * calling the constructor. * @function * @param {Object} event @@ -1092,16 +1092,13 @@ if ( tracker.stopHandler ) { event = $.getEvent( event ); - var propagate = tracker.stopHandler( { + tracker.stopHandler( { eventSource: tracker, position: getMouseRelative( event, tracker.element ), isTouchEvent: false, originalEvent: event, userData: tracker.userData } ); - if ( propagate === false ) { - $.cancelEvent( event ); - } } } From 3f5db8f8de07047ade61a1f3de2680ab620d7255 Mon Sep 17 00:00:00 2001 From: Antoine Vandecreme Date: Thu, 31 Oct 2013 16:16:08 -0400 Subject: [PATCH 3/3] Fix mousestop event on IE --- src/mousetracker.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/mousetracker.js b/src/mousetracker.js index 4ce7e82c..f0a91ff5 100644 --- a/src/mousetracker.js +++ b/src/mousetracker.js @@ -1088,15 +1088,13 @@ * @private * @inner */ - function onMouseStop( tracker, event ) { + function onMouseStop( tracker, originalMoveEvent ) { if ( tracker.stopHandler ) { - event = $.getEvent( event ); - tracker.stopHandler( { eventSource: tracker, - position: getMouseRelative( event, tracker.element ), + position: getMouseRelative( originalMoveEvent, tracker.element ), isTouchEvent: false, - originalEvent: event, + originalEvent: originalMoveEvent, userData: tracker.userData } ); }