Original Events in Handlers

Documentation fixes
isTouchEvent property removed from eventData where not used
'eventOrTouchPoint' var name used and 'originalEvent' var name restored
to 'event'
This commit is contained in:
Mark Salsbery 2013-09-12 10:05:50 -07:00
parent af078f8f19
commit 56ef12e850
2 changed files with 137 additions and 112 deletions

View File

@ -55,7 +55,7 @@ $.EventHandler.prototype = {
* @function * @function
* @param {String} eventName - Name of event to register. * @param {String} eventName - Name of event to register.
* @param {Function} handler - Function to call when event is triggered. * @param {Function} handler - Function to call when event is triggered.
* @param {Object} optional userData - Arbitrary object to be passed unchanged to the handler. * @param {Object} [userData=null] - Arbitrary object to be passed unchanged to the handler.
*/ */
addHandler: function ( eventName, handler, userData ) { addHandler: function ( eventName, handler, userData ) {
var events = this.events[ eventName ]; var events = this.events[ eventName ];

View File

@ -86,6 +86,8 @@
* An optional handler for focus. * An optional handler for focus.
* @param {Function} options.blurHandler * @param {Function} options.blurHandler
* An optional handler for blur. * An optional handler for blur.
* @param {Object} [options.userData=null]
* Arbitrary object to be passed unchanged to any attached handler methods.
* @property {Number} hash * @property {Number} hash
* An unique hash for this tracker. * An unique hash for this tracker.
* @property {Element} element * @property {Element} element
@ -96,8 +98,6 @@
* @property {Number} clickDistThreshold * @property {Number} 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.
* @property {Object} optional userData
* Arbitrary object to be passed unchanged to any attached handler methods.
*/ */
$.MouseTracker = function ( options ) { $.MouseTracker = function ( options ) {
@ -225,14 +225,19 @@
* @param {OpenSeadragon.MouseTracker} tracker * @param {OpenSeadragon.MouseTracker} tracker
* A reference to the tracker instance. * A reference to the tracker instance.
* @param {Object} eventData * @param {Object} eventData
* { * @param {OpenSeadragon.Point} eventData.position
* position: The position of the event relative to the tracked element. * The position of the event relative to the tracked element.
* insideElementPressed: True if the left mouse button is currently being pressed and was initiated inside the tracked element, otherwise false. * @param {Boolean} eventData.insideElementPressed
* buttonDownAny: Was the button down anywhere in the screen during the event. * True if the left mouse button is currently being pressed and was
* isTouchEvent: True if the original event is a touch event, otherwise false. * initiated inside the tracked element, otherwise false.
* originalEvent: The original event object. * @param {Boolean} eventData.buttonDownAny
* userData: Arbitrary user-defined object. * Was the button down anywhere in the screen during the event.
* } * @param {Boolean} eventData.isTouchEvent
* True if the original event is a touch event, otherwise false.
* @param {Object} eventData.originalEvent
* The original event object.
* @param {Object} eventData.userData
* Arbitrary user-defined object.
*/ */
enterHandler: function () { }, enterHandler: function () { },
@ -243,14 +248,19 @@
* @param {OpenSeadragon.MouseTracker} tracker * @param {OpenSeadragon.MouseTracker} tracker
* A reference to the tracker instance. * A reference to the tracker instance.
* @param {Object} eventData * @param {Object} eventData
* { * @param {OpenSeadragon.Point} eventData.position
* position: The position of the event relative to the tracked element. * The position of the event relative to the tracked element.
* insideElementPressed: True if the left mouse button is currently being pressed and was initiated inside the tracked element, otherwise false. * @param {Boolean} eventData.insideElementPressed
* buttonDownAny: Was the button down anywhere in the screen during the event. * True if the left mouse button is currently being pressed and was
* isTouchEvent: True if the original event is a touch event, otherwise false. * initiated inside the tracked element, otherwise false.
* originalEvent: The original event object. * @param {Boolean} eventData.buttonDownAny
* userData: Arbitrary user-defined object. * Was the button down anywhere in the screen during the event.
* } * @param {Boolean} eventData.isTouchEvent
* True if the original event is a touch event, otherwise false.
* @param {Object} eventData.originalEvent
* The original event object.
* @param {Object} eventData.userData
* Arbitrary user-defined object.
*/ */
exitHandler: function () { }, exitHandler: function () { },
@ -261,12 +271,14 @@
* @param {OpenSeadragon.MouseTracker} tracker * @param {OpenSeadragon.MouseTracker} tracker
* A reference to the tracker instance. * A reference to the tracker instance.
* @param {Object} eventData * @param {Object} eventData
* { * @param {OpenSeadragon.Point} eventData.position
* position: The position of the event relative to the tracked element. * The position of the event relative to the tracked element.
* isTouchEvent: True if the original event is a touch event, otherwise false. * @param {Boolean} eventData.isTouchEvent
* originalEvent: The original event object. * True if the original event is a touch event, otherwise false.
* userData: Arbitrary user-defined object. * @param {Object} eventData.originalEvent
* } * The original event object.
* @param {Object} eventData.userData
* Arbitrary user-defined object.
*/ */
pressHandler: function () { }, pressHandler: function () { },
@ -277,14 +289,19 @@
* @param {OpenSeadragon.MouseTracker} tracker * @param {OpenSeadragon.MouseTracker} tracker
* A reference to the tracker instance. * A reference to the tracker instance.
* @param {Object} eventData * @param {Object} eventData
* { * @param {OpenSeadragon.Point} eventData.position
* position: The position of the event relative to the tracked element. * The position of the event relative to the tracked element.
* insideElementPressed: True if the left mouse button is currently being pressed and was initiated inside the tracked element, otherwise false. * @param {Boolean} eventData.insideElementPressed
* insideElementReleased: Was the mouse still inside the tracked element when the button was released. * True if the left mouse button is currently being pressed and was
* isTouchEvent: True if the original event is a touch event, otherwise false. * initiated inside the tracked element, otherwise false.
* originalEvent: The original event object. * @param {Boolean} eventData.insideElementReleased
* userData: Arbitrary user-defined object. * True if the cursor still inside the tracked element when the button was released.
* } * @param {Boolean} eventData.isTouchEvent
* True if the original event is a touch event, otherwise false.
* @param {Object} eventData.originalEvent
* The original event object.
* @param {Object} eventData.userData
* Arbitrary user-defined object.
*/ */
releaseHandler: function () { }, releaseHandler: function () { },
@ -295,12 +312,14 @@
* @param {OpenSeadragon.MouseTracker} tracker * @param {OpenSeadragon.MouseTracker} tracker
* A reference to the tracker instance. * A reference to the tracker instance.
* @param {Object} eventData * @param {Object} eventData
* { * @param {OpenSeadragon.Point} eventData.position
* position: The position of the event relative to the tracked element. * The position of the event relative to the tracked element.
* isTouchEvent: True if the original event is a touch event, otherwise false. * @param {Boolean} eventData.isTouchEvent
* originalEvent: The original event object. * True if the original event is a touch event, otherwise false.
* userData: Arbitrary user-defined object. * @param {Object} eventData.originalEvent
* } * The original event object.
* @param {Object} eventData.userData
* Arbitrary user-defined object.
*/ */
moveHandler: function () { }, moveHandler: function () { },
@ -311,14 +330,18 @@
* @param {OpenSeadragon.MouseTracker} tracker * @param {OpenSeadragon.MouseTracker} tracker
* A reference to the tracker instance. * A reference to the tracker instance.
* @param {Object} eventData * @param {Object} eventData
* { * @param {OpenSeadragon.Point} eventData.position
* position: The position of the event relative to the tracked element. * The position of the event relative to the tracked element.
* scroll: The scroll delta for the event. * @param {Number} eventData.scroll
* shift: Was the shift key being pressed during this event? * The scroll delta for the event.
* isTouchEvent: True if the original event is a touch event, otherwise false. * @param {Boolean} eventData.shift
* originalEvent: The original event object. * True if the shift key was pressed during this event.
* userData: Arbitrary user-defined object. * @param {Boolean} eventData.isTouchEvent
* } * True if the original event is a touch event, otherwise false.
* @param {Object} eventData.originalEvent
* The original event object.
* @param {Object} eventData.userData
* Arbitrary user-defined object.
*/ */
scrollHandler: function () { }, scrollHandler: function () { },
@ -329,14 +352,18 @@
* @param {OpenSeadragon.MouseTracker} tracker * @param {OpenSeadragon.MouseTracker} tracker
* A reference to the tracker instance. * A reference to the tracker instance.
* @param {Object} eventData * @param {Object} eventData
* { * @param {OpenSeadragon.Point} eventData.position
* position: The position of the event relative to the tracked element. * The position of the event relative to the tracked element.
* quick: True only if the clickDistThreshold and clickDeltaThreshold are both pased. Useful for ignoring events. * @param {Number} eventData.quick
* shift: Was the shift key being pressed during this event? * True only if the clickDistThreshold and clickDeltaThreshold are both pased. Useful for ignoring events.
* isTouchEvent: True if the original event is a touch event, otherwise false. * @param {Boolean} eventData.shift
* originalEvent: The original event object. * True if the shift key was pressed during this event.
* userData: Arbitrary user-defined object. * @param {Boolean} eventData.isTouchEvent
* } * True if the original event is a touch event, otherwise false.
* @param {Object} eventData.originalEvent
* The original event object.
* @param {Object} eventData.userData
* Arbitrary user-defined object.
*/ */
clickHandler: function () { }, clickHandler: function () { },
@ -347,14 +374,18 @@
* @param {OpenSeadragon.MouseTracker} tracker * @param {OpenSeadragon.MouseTracker} tracker
* A reference to the tracker instance. * A reference to the tracker instance.
* @param {Object} eventData * @param {Object} eventData
* { * @param {OpenSeadragon.Point} eventData.position
* position: The position of the event relative to the tracked element. * The position of the event relative to the tracked element.
* delta: The x,y components of the difference between start drag and end drag. Usefule for ignoring or weighting the events. * @param {OpenSeadragon.Point} eventData.delta
* shift: Was the shift key being pressed during this event? * The x,y components of the difference between start drag and end drag. Usefule for ignoring or weighting the events.
* isTouchEvent: True if the original event is a touch event, otherwise false. * @param {Boolean} eventData.shift
* originalEvent: The original event object. * True if the shift key was pressed during this event.
* userData: Arbitrary user-defined object. * @param {Boolean} eventData.isTouchEvent
* } * True if the original event is a touch event, otherwise false.
* @param {Object} eventData.originalEvent
* The original event object.
* @param {Object} eventData.userData
* Arbitrary user-defined object.
*/ */
dragHandler: function () { }, dragHandler: function () { },
@ -365,13 +396,14 @@
* @param {OpenSeadragon.MouseTracker} tracker * @param {OpenSeadragon.MouseTracker} tracker
* A reference to the tracker instance. * A reference to the tracker instance.
* @param {Object} eventData * @param {Object} eventData
* { * @param {Number} eventData.keyCode
* keyCode: The key code that was pressed. * The key code that was pressed.
* shift: Was the shift key being pressed during this event? * @param {Boolean} eventData.shift
* isTouchEvent: True if the original event is a touch event, otherwise false. * True if the shift key was pressed during this event.
* originalEvent: The original event object. * @param {Object} eventData.originalEvent
* userData: Arbitrary user-defined object. * The original event object.
* } * @param {Object} eventData.userData
* Arbitrary user-defined object.
*/ */
keyHandler: function () { }, keyHandler: function () { },
@ -382,11 +414,10 @@
* @param {OpenSeadragon.MouseTracker} tracker * @param {OpenSeadragon.MouseTracker} tracker
* A reference to the tracker instance. * A reference to the tracker instance.
* @param {Object} eventData * @param {Object} eventData
* { * @param {Object} eventData.originalEvent
* isTouchEvent: True if the original event is a touch event, otherwise false. * The original event object.
* originalEvent: The original event object. * @param {Object} eventData.userData
* userData: Arbitrary user-defined object. * Arbitrary user-defined object.
* }
*/ */
focusHandler: function () { }, focusHandler: function () { },
@ -397,11 +428,10 @@
* @param {OpenSeadragon.MouseTracker} tracker * @param {OpenSeadragon.MouseTracker} tracker
* A reference to the tracker instance. * A reference to the tracker instance.
* @param {Object} eventData * @param {Object} eventData
* { * @param {Object} eventData.originalEvent
* isTouchEvent: True if the original event is a touch event, otherwise false. * The original event object.
* originalEvent: The original event object. * @param {Object} eventData.userData
* userData: Arbitrary user-defined object. * Arbitrary user-defined object.
* }
*/ */
blurHandler: function () { } blurHandler: function () { }
}; };
@ -601,7 +631,6 @@
propagate = tracker.focusHandler( propagate = tracker.focusHandler(
tracker, tracker,
{ {
isTouchEvent: false,
originalEvent: event, originalEvent: event,
userData: tracker.userData userData: tracker.userData
} }
@ -624,7 +653,6 @@
propagate = tracker.blurHandler( propagate = tracker.blurHandler(
tracker, tracker,
{ {
isTouchEvent: false,
originalEvent: event, originalEvent: event,
userData: tracker.userData userData: tracker.userData
} }
@ -650,7 +678,6 @@
position: getMouseRelative( event, tracker.element ), position: getMouseRelative( event, tracker.element ),
keyCode: event.keyCode ? event.keyCode : event.charCode, keyCode: event.keyCode ? event.keyCode : event.charCode,
shift: event.shiftKey, shift: event.shiftKey,
isTouchEvent: false,
originalEvent: event, originalEvent: event,
userData: tracker.userData userData: tracker.userData
} }
@ -785,9 +812,9 @@
isTouch = isTouch || false; isTouch = isTouch || false;
var originalEvent = $.getEvent(event); event = $.getEvent(event);
event = isTouch ? event.touches[ 0 ] : event; var eventOrTouchPoint = isTouch ? event.touches[ 0 ] : event;
if ( event.button == 2 ) { if ( event.button == 2 ) {
return; return;
@ -795,7 +822,7 @@
delegate.insideElementPressed = true; delegate.insideElementPressed = true;
delegate.lastPoint = getMouseAbsolute( event ); delegate.lastPoint = getMouseAbsolute( eventOrTouchPoint );
delegate.lastMouseDownPoint = delegate.lastPoint; delegate.lastMouseDownPoint = delegate.lastPoint;
delegate.lastMouseDownTime = $.now(); delegate.lastMouseDownTime = $.now();
@ -803,19 +830,19 @@
propagate = tracker.pressHandler( propagate = tracker.pressHandler(
tracker, tracker,
{ {
position: getMouseRelative( event, tracker.element ), position: getMouseRelative( eventOrTouchPoint, tracker.element ),
isTouchEvent: isTouch, isTouchEvent: isTouch,
originalEvent: originalEvent, originalEvent: event,
userData: tracker.userData userData: tracker.userData
} }
); );
if ( propagate === false ) { if ( propagate === false ) {
$.cancelEvent( originalEvent ); $.cancelEvent( event );
} }
} }
if ( tracker.pressHandler || tracker.dragHandler ) { if ( tracker.pressHandler || tracker.dragHandler ) {
$.cancelEvent( originalEvent ); $.cancelEvent( event );
} }
if ( noCapture ) { if ( noCapture ) {
@ -886,9 +913,7 @@
isTouch = isTouch || false; isTouch = isTouch || false;
var originalEvent = $.getEvent(event); event = $.getEvent(event);
event = isTouch ? event.changedTouches[ 0 ] : event;
if ( event.button == 2 ) { if ( event.button == 2 ) {
return; return;
@ -900,21 +925,21 @@
propagate = tracker.releaseHandler( propagate = tracker.releaseHandler(
tracker, tracker,
{ {
position: getMouseRelative( event, tracker.element ), position: getMouseRelative( isTouch ? event.changedTouches[ 0 ] : event, tracker.element ),
insideElementPressed: insideElementPressed, insideElementPressed: insideElementPressed,
insideElementReleased: insideElementReleased, insideElementReleased: insideElementReleased,
isTouchEvent: isTouch, isTouchEvent: isTouch,
originalEvent: originalEvent, originalEvent: event,
userData: tracker.userData userData: tracker.userData
} }
); );
if ( propagate === false ) { if ( propagate === false ) {
$.cancelEvent( originalEvent ); $.cancelEvent( event );
} }
} }
if ( insideElementPressed && insideElementReleased ) { if ( insideElementPressed && insideElementReleased ) {
handleMouseClick( tracker, originalEvent, isTouch ); handleMouseClick( tracker, event, isTouch );
} }
} }
@ -1101,16 +1126,16 @@
isTouch = isTouch || false; isTouch = isTouch || false;
var originalEvent = $.getEvent( event ); event = $.getEvent( event );
event = isTouch ? event.changedTouches[0] : event; var eventOrTouchPoint = isTouch ? event.changedTouches[0] : event;
if ( event.button == 2 ) { if ( event.button == 2 ) {
return; return;
} }
var time = $.now() - delegate.lastMouseDownTime, var time = $.now() - delegate.lastMouseDownTime,
point = getMouseAbsolute( event ), point = getMouseAbsolute( eventOrTouchPoint ),
distance = delegate.lastMouseDownPoint.distanceTo( point ), distance = delegate.lastMouseDownPoint.distanceTo( point ),
quick = time <= tracker.clickTimeThreshold && quick = time <= tracker.clickTimeThreshold &&
distance <= tracker.clickDistThreshold; distance <= tracker.clickDistThreshold;
@ -1119,16 +1144,16 @@
propagate = tracker.clickHandler( propagate = tracker.clickHandler(
tracker, tracker,
{ {
position: getMouseRelative( event, tracker.element ), position: getMouseRelative( eventOrTouchPoint, tracker.element ),
quick: quick, quick: quick,
shift: originalEvent.shiftKey, shift: event.shiftKey,
isTouchEvent: isTouch, isTouchEvent: isTouch,
originalEvent: originalEvent, originalEvent: event,
userData: tracker.userData userData: tracker.userData
} }
); );
if ( propagate === false ) { if ( propagate === false ) {
$.cancelEvent( originalEvent ); $.cancelEvent( event );
} }
} }
} }
@ -1146,9 +1171,9 @@
isTouch = isTouch || false; isTouch = isTouch || false;
var originalEvent = $.getEvent(event); event = $.getEvent(event);
event = isTouch ? event.touches[0] : event; var eventOrTouchPoint = isTouch ? event.touches[0] : event;
point = getMouseAbsolute( event ); point = getMouseAbsolute( eventOrTouchPoint );
delta = point.minus( delegate.lastPoint ); delta = point.minus( delegate.lastPoint );
delegate.lastPoint = point; delegate.lastPoint = point;
@ -1157,16 +1182,16 @@
propagate = tracker.dragHandler( propagate = tracker.dragHandler(
tracker, tracker,
{ {
position: getMouseRelative( event, tracker.element ), position: getMouseRelative( eventOrTouchPoint, tracker.element ),
delta: delta, delta: delta,
shift: originalEvent.shiftKey, shift: event.shiftKey,
isTouchEvent: isTouch, isTouchEvent: isTouch,
originalEvent: originalEvent, originalEvent: event,
userData: tracker.userData userData: tracker.userData
} }
); );
if ( propagate === false ) { if ( propagate === false ) {
$.cancelEvent( originalEvent ); $.cancelEvent( event );
} }
} }
} }