Add mouse stop event

This commit is contained in:
Antoine Vandecreme 2013-10-22 16:54:04 -04:00
parent 574aa0f4f1
commit 8debb26d61

View File

@ -59,11 +59,14 @@
* A reference to an element or an element id for which the mouse * A reference to an element or an element id for which the mouse
* events will be monitored. * events will be monitored.
* @param {Number} options.clickTimeThreshold * @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. * will be treated as a single event.
* @param {Number} options.clickDistThreshold * @param {Number} options.clickDistThreshold
* The distance between mouse click within multiple mouse clicks * The distance between mouse click within multiple mouse clicks
* will be treated as a single event. * 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 * @param {Function} options.enterHandler
* An optional handler for mouse enter. * An optional handler for mouse enter.
* @param {Function} options.exitHandler * @param {Function} options.exitHandler
@ -116,6 +119,7 @@
this.clickTimeThreshold = options.clickTimeThreshold; this.clickTimeThreshold = options.clickTimeThreshold;
this.clickDistThreshold = options.clickDistThreshold; this.clickDistThreshold = options.clickDistThreshold;
this.userData = options.userData || null; this.userData = options.userData || null;
this.stopDelay = options.stopDelay || 50;
this.enterHandler = options.enterHandler || null; this.enterHandler = options.enterHandler || null;
this.exitHandler = options.exitHandler || null; this.exitHandler = options.exitHandler || null;
@ -125,6 +129,7 @@
this.scrollHandler = options.scrollHandler || null; this.scrollHandler = options.scrollHandler || null;
this.clickHandler = options.clickHandler || null; this.clickHandler = options.clickHandler || null;
this.dragHandler = options.dragHandler || null; this.dragHandler = options.dragHandler || null;
this.stopHandler = options.stopHandler || null;
this.keyHandler = options.keyHandler || null; this.keyHandler = options.keyHandler || null;
this.focusHandler = options.focusHandler || null; this.focusHandler = options.focusHandler || null;
this.blurHandler = options.blurHandler || null; this.blurHandler = options.blurHandler || null;
@ -389,6 +394,24 @@
*/ */
dragHandler: function () { }, 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 * Implement or assign implmentation to these handlers during or after
* calling the constructor. * calling the constructor.
@ -1053,8 +1076,34 @@
$.cancelEvent( event ); $.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 * @private