Merge branch 'Original-Events-In-Handlers' of github.com:msalsbery/openseadragon into msalsbery-Original-Events-In-Handlers

Fixed Conflicts:
	changelog.txt
This commit is contained in:
Ian Gilman 2013-09-24 10:28:46 -07:00
commit 6396fe1504
11 changed files with 819 additions and 495 deletions

View File

@ -3,6 +3,11 @@ OPENSEADRAGON CHANGELOG
1.0.0: (in progress) 1.0.0: (in progress)
* MouseTracker now passes the original event objects to its handler methods (#23)
* Breaking change: MouseTracker event handler method signatures changed to 'handlerMethod( tracker, eventData)' (#23)
* MouseTracker now supports an optional 'moveHandler' method for tracking mousemove events (#215)
* Fixed: Element-relative mouse coordinates now correct if the element and/or page is scrolled (using new OpenSeadragon.getElementOffset() method) (#131)
0.9.131: 0.9.131:
* Fixed: canvas-click event shouldn't fire as you drag (#198) * Fixed: canvas-click event shouldn't fire as you drag (#198)

View File

@ -175,57 +175,57 @@ $.Button = function( options ) {
clickTimeThreshold: this.clickTimeThreshold, clickTimeThreshold: this.clickTimeThreshold,
clickDistThreshold: this.clickDistThreshold, clickDistThreshold: this.clickDistThreshold,
enterHandler: function( tracker, position, buttonDownElement, buttonDownAny ) { enterHandler: function( tracker, eventData ) {
if ( buttonDownElement ) { if ( eventData.insideElementPressed ) {
inTo( _this, $.ButtonState.DOWN ); inTo( _this, $.ButtonState.DOWN );
_this.raiseEvent( "onEnter", _this ); _this.raiseEvent( "onEnter", _this );
} else if ( !buttonDownAny ) { } else if ( !eventData.buttonDownAny ) {
inTo( _this, $.ButtonState.HOVER ); inTo( _this, $.ButtonState.HOVER );
} }
}, },
focusHandler: function( tracker, position, buttonDownElement, buttonDownAny ) { focusHandler: function ( tracker, eventData ) {
this.enterHandler( tracker, position, buttonDownElement, buttonDownAny ); this.enterHandler( tracker, eventData );
_this.raiseEvent( "onFocus", _this ); _this.raiseEvent( "onFocus", _this );
}, },
exitHandler: function( tracker, position, buttonDownElement, buttonDownAny ) { exitHandler: function( tracker, eventData ) {
outTo( _this, $.ButtonState.GROUP ); outTo( _this, $.ButtonState.GROUP );
if ( buttonDownElement ) { if ( eventData.insideElementPressed ) {
_this.raiseEvent( "onExit", _this ); _this.raiseEvent( "onExit", _this );
} }
}, },
blurHandler: function( tracker, position, buttonDownElement, buttonDownAny ) { blurHandler: function ( tracker, eventData ) {
this.exitHandler( tracker, position, buttonDownElement, buttonDownAny ); this.exitHandler( tracker, eventData );
_this.raiseEvent( "onBlur", _this ); _this.raiseEvent( "onBlur", _this );
}, },
pressHandler: function( tracker, position ) { pressHandler: function ( tracker, eventData ) {
inTo( _this, $.ButtonState.DOWN ); inTo( _this, $.ButtonState.DOWN );
_this.raiseEvent( "onPress", _this ); _this.raiseEvent( "onPress", _this );
}, },
releaseHandler: function( tracker, position, insideElementPress, insideElementRelease ) { releaseHandler: function( tracker, eventData ) {
if ( insideElementPress && insideElementRelease ) { if ( eventData.insideElementPressed && eventData.insideElementReleased ) {
outTo( _this, $.ButtonState.HOVER ); outTo( _this, $.ButtonState.HOVER );
_this.raiseEvent( "onRelease", _this ); _this.raiseEvent( "onRelease", _this );
} else if ( insideElementPress ) { } else if ( eventData.insideElementPressed ) {
outTo( _this, $.ButtonState.GROUP ); outTo( _this, $.ButtonState.GROUP );
} else { } else {
inTo( _this, $.ButtonState.HOVER ); inTo( _this, $.ButtonState.HOVER );
} }
}, },
clickHandler: function( tracker, position, quick, shift ) { clickHandler: function( tracker, eventData ) {
if ( quick ) { if ( eventData.quick ) {
_this.raiseEvent("onClick", _this); _this.raiseEvent("onClick", _this);
} }
}, },
keyHandler: function( tracker, key ){ keyHandler: function( tracker, eventData ){
//console.log( "%s : handling key %s!", _this.tooltip, key); //console.log( "%s : handling key %s!", _this.tooltip, eventData.keyCode);
if( 13 === key ){ if( 13 === eventData.keyCode ){
_this.raiseEvent( "onClick", _this ); _this.raiseEvent( "onClick", _this );
_this.raiseEvent( "onRelease", _this ); _this.raiseEvent( "onRelease", _this );
return false; return false;

View File

@ -85,29 +85,23 @@ $.ButtonGroup = function( options ) {
element: this.element, element: this.element,
clickTimeThreshold: this.clickTimeThreshold, clickTimeThreshold: this.clickTimeThreshold,
clickDistThreshold: this.clickDistThreshold, clickDistThreshold: this.clickDistThreshold,
enterHandler: function() { enterHandler: function ( tracker, eventData ) {
var i; var i;
for ( i = 0; i < _this.buttons.length; i++ ) { for ( i = 0; i < _this.buttons.length; i++ ) {
_this.buttons[ i ].notifyGroupEnter(); _this.buttons[ i ].notifyGroupEnter();
} }
}, },
exitHandler: function() { exitHandler: function ( tracker, eventData ) {
var i, var i;
buttonDownElement = arguments.length > 2 ? if ( !eventData.insideElementPressed ) {
arguments[ 2 ] :
null;
if ( !buttonDownElement ) {
for ( i = 0; i < _this.buttons.length; i++ ) { for ( i = 0; i < _this.buttons.length; i++ ) {
_this.buttons[ i ].notifyGroupExit(); _this.buttons[ i ].notifyGroupExit();
} }
} }
}, },
releaseHandler: function() { releaseHandler: function ( tracker, eventData ) {
var i, var i;
insideElementRelease = arguments.length > 3 ? if ( !eventData.insideElementReleased ) {
arguments[ 3 ] :
null;
if ( !insideElementRelease ) {
for ( i = 0; i < _this.buttons.length; i++ ) { for ( i = 0; i < _this.buttons.length; i++ ) {
_this.buttons[ i ].notifyGroupExit(); _this.buttons[ i ].notifyGroupExit();
} }
@ -125,7 +119,7 @@ $.ButtonGroup.prototype = {
* @name OpenSeadragon.ButtonGroup.prototype.emulateEnter * @name OpenSeadragon.ButtonGroup.prototype.emulateEnter
*/ */
emulateEnter: function() { emulateEnter: function() {
this.tracker.enterHandler(); this.tracker.enterHandler( this.tracker, {} );
}, },
/** /**
@ -135,7 +129,7 @@ $.ButtonGroup.prototype = {
* @name OpenSeadragon.ButtonGroup.prototype.emulateExit * @name OpenSeadragon.ButtonGroup.prototype.emulateExit
*/ */
emulateExit: function() { emulateExit: function() {
this.tracker.exitHandler(); this.tracker.exitHandler( this.tracker, {} );
} }
}; };

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 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

@ -72,12 +72,22 @@
* An optional handler for mouse press. * An optional handler for mouse press.
* @param {Function} options.releaseHandler * @param {Function} options.releaseHandler
* An optional handler for mouse release. * An optional handler for mouse release.
* @param {Function} options.moveHandler
* An optional handler for mouse move.
* @param {Function} options.scrollHandler * @param {Function} options.scrollHandler
* An optional handler for mouse scroll. * An optional handler for mouse scroll.
* @param {Function} options.clickHandler * @param {Function} options.clickHandler
* An optional handler for mouse click. * An optional handler for mouse click.
* @param {Function} options.dragHandler * @param {Function} options.dragHandler
* An optional handler for mouse drag. * An optional handler for mouse drag.
* @param {Function} options.keyHandler
* An optional handler for keypress.
* @param {Function} options.focusHandler
* An optional handler for focus.
* @param {Function} options.blurHandler
* 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
@ -105,12 +115,13 @@
this.element = $.getElement( options.element ); this.element = $.getElement( options.element );
this.clickTimeThreshold = options.clickTimeThreshold; this.clickTimeThreshold = options.clickTimeThreshold;
this.clickDistThreshold = options.clickDistThreshold; this.clickDistThreshold = options.clickDistThreshold;
this.userData = options.userData || null;
this.enterHandler = options.enterHandler || null; this.enterHandler = options.enterHandler || null;
this.exitHandler = options.exitHandler || null; this.exitHandler = options.exitHandler || null;
this.pressHandler = options.pressHandler || null; this.pressHandler = options.pressHandler || null;
this.releaseHandler = options.releaseHandler || null; this.releaseHandler = options.releaseHandler || null;
this.moveHandler = options.moveHandler || null;
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;
@ -127,7 +138,7 @@
* Are we currently tracking mouse events. * Are we currently tracking mouse events.
* @property {Boolean} capturing * @property {Boolean} capturing
* Are we curruently capturing mouse events. * Are we curruently capturing mouse events.
* @property {Boolean} buttonDown * @property {Boolean} insideElementPressed
* True if the left mouse button is currently being pressed and was * True if the left mouse button is currently being pressed and was
* initiated inside the tracked element, otherwise false. * initiated inside the tracked element, otherwise false.
* @property {Boolean} insideElement * @property {Boolean} insideElement
@ -140,17 +151,18 @@
* Position of last mouse down * Position of last mouse down
*/ */
THIS[ this.hash ] = { THIS[ this.hash ] = {
mouseover: function( event ){ onMouseOver( _this, event ); }, mouseover: function ( event ) { onMouseOver( _this, event, false ); },
mouseout: function( event ){ onMouseOut( _this, event ); }, mouseout: function ( event ) { onMouseOut( _this, event, false ); },
mousedown: function ( event ) { onMouseDown( _this, event ); }, mousedown: function ( event ) { onMouseDown( _this, event ); },
mouseup: function( event ){ onMouseUp( _this, event ); }, mouseup: function ( event ) { onMouseUp( _this, event, false ); },
click: function( event ){ onMouseClick( _this, event ); },
DOMMouseScroll: function( event ){ onMouseWheelSpin( _this, event ); },
mousewheel: function( event ){ onMouseWheelSpin( _this, event ); },
mouseupie: function( event ){ onMouseUpIE( _this, event ); },
mousemoveie: function( event ){ onMouseMoveIE( _this, event ); },
mouseupwindow: function( event ){ onMouseUpWindow( _this, event ); },
mousemove: function ( event ) { onMouseMove( _this, event ); }, mousemove: function ( event ) { onMouseMove( _this, event ); },
click: function ( event ) { onMouseClick( _this, event ); },
DOMMouseScroll: function ( event ) { onMouseWheelSpin( _this, event, false ); },
mousewheel: function ( event ) { onMouseWheelSpin( _this, event, false ); },
mouseupie: function ( event ) { onMouseUpIE( _this, event ); },
mousemovecapturedie: function ( event ) { onMouseMoveCapturedIE( _this, event ); },
mouseupcaptured: function ( event ) { onMouseUpCaptured( _this, event ); },
mousemovecaptured: function ( event ) { onMouseMoveCaptured( _this, event, false ); },
touchstart: function ( event ) { onTouchStart( _this, event ); }, touchstart: function ( event ) { onTouchStart( _this, event ); },
touchmove: function ( event ) { onTouchMove( _this, event ); }, touchmove: function ( event ) { onTouchMove( _this, event ); },
touchend: function ( event ) { onTouchEnd( _this, event ); }, touchend: function ( event ) { onTouchEnd( _this, event ); },
@ -159,7 +171,7 @@
blur: function ( event ) { onBlur( _this, event ); }, blur: function ( event ) { onBlur( _this, event ); },
tracking: false, tracking: false,
capturing: false, capturing: false,
buttonDown: false, insideElementPressed: false,
insideElement: false, insideElement: false,
lastPoint: null, lastPoint: null,
lastMouseDownTime: null, lastMouseDownTime: null,
@ -212,13 +224,20 @@
* @function * @function
* @param {OpenSeadragon.MouseTracker} tracker * @param {OpenSeadragon.MouseTracker} tracker
* A reference to the tracker instance. * A reference to the tracker instance.
* @param {OpenSeadragon.Point} position * @param {Object} eventData
* The poistion of the event on the screen. * @param {OpenSeadragon.Point} eventData.position
* @param {Boolean} buttonDown * The position of the event relative to the tracked element.
* @param {Boolean} eventData.insideElementPressed
* True if the left mouse button is currently being pressed and was * True if the left mouse button is currently being pressed and was
* initiated inside the tracked element, otherwise false. * initiated inside the tracked element, otherwise false.
* @param {Boolean} buttonDownAny * @param {Boolean} eventData.buttonDownAny
* Was the button down anywhere in the screen during the event. * 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 () { },
@ -228,13 +247,20 @@
* @function * @function
* @param {OpenSeadragon.MouseTracker} tracker * @param {OpenSeadragon.MouseTracker} tracker
* A reference to the tracker instance. * A reference to the tracker instance.
* @param {OpenSeadragon.Point} position * @param {Object} eventData
* The poistion of the event on the screen. * @param {OpenSeadragon.Point} eventData.position
* @param {Boolean} buttonDown * The position of the event relative to the tracked element.
* @param {Boolean} eventData.insideElementPressed
* True if the left mouse button is currently being pressed and was * True if the left mouse button is currently being pressed and was
* initiated inside the tracked element, otherwise false. * initiated inside the tracked element, otherwise false.
* @param {Boolean} buttonDownAny * @param {Boolean} eventData.buttonDownAny
* Was the button down anywhere in the screen during the event. * 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 () { },
@ -244,8 +270,15 @@
* @function * @function
* @param {OpenSeadragon.MouseTracker} tracker * @param {OpenSeadragon.MouseTracker} tracker
* A reference to the tracker instance. * A reference to the tracker instance.
* @param {OpenSeadragon.Point} position * @param {Object} eventData
* The poistion of the event on the screen. * @param {OpenSeadragon.Point} eventData.position
* The position of the event relative to the tracked element.
* @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.
*/ */
pressHandler: function () { }, pressHandler: function () { },
@ -255,14 +288,20 @@
* @function * @function
* @param {OpenSeadragon.MouseTracker} tracker * @param {OpenSeadragon.MouseTracker} tracker
* A reference to the tracker instance. * A reference to the tracker instance.
* @param {OpenSeadragon.Point} position * @param {Object} eventData
* The poistion of the event on the screen. * @param {OpenSeadragon.Point} eventData.position
* @param {Boolean} buttonDown * The position of the event relative to the tracked element.
* @param {Boolean} eventData.insideElementPressed
* True if the left mouse button is currently being pressed and was * True if the left mouse button is currently being pressed and was
* initiated inside the tracked element, otherwise false. * initiated inside the tracked element, otherwise false.
* @param {Boolean} insideElementRelease * @param {Boolean} eventData.insideElementReleased
* Was the mouse still inside the tracked element when the button * True if the cursor still inside the tracked element when the button was released.
* 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 () { },
@ -272,12 +311,37 @@
* @function * @function
* @param {OpenSeadragon.MouseTracker} tracker * @param {OpenSeadragon.MouseTracker} tracker
* A reference to the tracker instance. * A reference to the tracker instance.
* @param {OpenSeadragon.Point} position * @param {Object} eventData
* The poistion of the event on the screen. * @param {OpenSeadragon.Point} eventData.position
* @param {Number} scroll * The position of the event relative to the tracked element.
* @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.
*/
moveHandler: function () { },
/**
* Implement or assign implmentation to these handlers during or after
* calling the constructor.
* @function
* @param {OpenSeadragon.MouseTracker} tracker
* A reference to the tracker instance.
* @param {Object} eventData
* @param {OpenSeadragon.Point} eventData.position
* The position of the event relative to the tracked element.
* @param {Number} eventData.scroll
* The scroll delta for the event. * The scroll delta for the event.
* @param {Boolean} shift * @param {Boolean} eventData.shift
* Was the shift key being pressed during this event? * True if the shift key was pressed during this 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.
*/ */
scrollHandler: function () { }, scrollHandler: function () { },
@ -287,13 +351,19 @@
* @function * @function
* @param {OpenSeadragon.MouseTracker} tracker * @param {OpenSeadragon.MouseTracker} tracker
* A reference to the tracker instance. * A reference to the tracker instance.
* @param {OpenSeadragon.Point} position * @param {Object} eventData
* The poistion of the event on the screen. * @param {OpenSeadragon.Point} eventData.position
* @param {Boolean} quick * The position of the event relative to the tracked element.
* True only if the clickDistThreshold and clickDeltaThreshold are * @param {Number} eventData.quick
* both pased. Useful for ignoring events. * True only if the clickDistThreshold and clickDeltaThreshold are both pased. Useful for ignoring events.
* @param {Boolean} shift * @param {Boolean} eventData.shift
* Was the shift key being pressed during this event? * True if the shift key was pressed during this 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.
*/ */
clickHandler: function () { }, clickHandler: function () { },
@ -303,13 +373,19 @@
* @function * @function
* @param {OpenSeadragon.MouseTracker} tracker * @param {OpenSeadragon.MouseTracker} tracker
* A reference to the tracker instance. * A reference to the tracker instance.
* @param {OpenSeadragon.Point} position * @param {Object} eventData
* The poistion of the event on the screen. * @param {OpenSeadragon.Point} eventData.position
* @param {OpenSeadragon.Point} delta * The position of the event relative to the tracked element.
* The x,y components of the difference between start drag and * @param {OpenSeadragon.Point} eventData.delta
* end drag. Usefule for ignoring or weighting the events. * The x,y components of the difference between start drag and end drag. Usefule for ignoring or weighting the events.
* @param {Boolean} shift * @param {Boolean} eventData.shift
* Was the shift key being pressed during this event? * True if the shift key was pressed during this 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.
*/ */
dragHandler: function () { }, dragHandler: function () { },
@ -319,15 +395,44 @@
* @function * @function
* @param {OpenSeadragon.MouseTracker} tracker * @param {OpenSeadragon.MouseTracker} tracker
* A reference to the tracker instance. * A reference to the tracker instance.
* @param {Number} keyCode * @param {Object} eventData
* @param {Number} eventData.keyCode
* The key code that was pressed. * The key code that was pressed.
* @param {Boolean} shift * @param {Boolean} eventData.shift
* Was the shift key being pressed during this event? * True if the shift key was pressed during this event.
* @param {Object} eventData.originalEvent
* The original event object.
* @param {Object} eventData.userData
* Arbitrary user-defined object.
*/ */
keyHandler: function () { }, keyHandler: function () { },
/**
* Implement or assign implmentation to these handlers during or after
* calling the constructor.
* @function
* @param {OpenSeadragon.MouseTracker} tracker
* A reference to the tracker instance.
* @param {Object} eventData
* @param {Object} eventData.originalEvent
* The original event object.
* @param {Object} eventData.userData
* Arbitrary user-defined object.
*/
focusHandler: function () { }, focusHandler: function () { },
/**
* Implement or assign implmentation to these handlers during or after
* calling the constructor.
* @function
* @param {OpenSeadragon.MouseTracker} tracker
* A reference to the tracker instance.
* @param {Object} eventData
* @param {Object} eventData.originalEvent
* The original event object.
* @param {Object} eventData.userData
* Arbitrary user-defined object.
*/
blurHandler: function () { } blurHandler: function () { }
}; };
@ -338,7 +443,7 @@
*/ */
function startTracking( tracker ) { function startTracking( tracker ) {
var events = [ var events = [
"mouseover", "mouseout", "mousedown", "mouseup", "mouseover", "mouseout", "mousedown", "mouseup", "mousemove",
"click", "click",
"DOMMouseScroll", "mousewheel", "DOMMouseScroll", "mousewheel",
"touchstart", "touchmove", "touchend", "touchstart", "touchmove", "touchend",
@ -371,7 +476,7 @@
*/ */
function stopTracking( tracker ) { function stopTracking( tracker ) {
var events = [ var events = [
"mouseover", "mouseout", "mousedown", "mouseup", "mouseover", "mouseout", "mousedown", "mouseup", "mousemove",
"click", "click",
"DOMMouseScroll", "mousewheel", "DOMMouseScroll", "mousewheel",
"touchstart", "touchmove", "touchend", "touchstart", "touchmove", "touchend",
@ -432,20 +537,20 @@
$.addEvent( $.addEvent(
tracker.element, tracker.element,
"mousemove", "mousemove",
delegate.mousemoveie, delegate.mousemovecapturedie,
true true
); );
} else { } else {
$.addEvent( $.addEvent(
window, window,
"mouseup", "mouseup",
delegate.mouseupwindow, delegate.mouseupcaptured,
true true
); );
$.addEvent( $.addEvent(
window, window,
"mousemove", "mousemove",
delegate.mousemove, delegate.mousemovecaptured,
true true
); );
} }
@ -467,7 +572,7 @@
$.removeEvent( $.removeEvent(
tracker.element, tracker.element,
"mousemove", "mousemove",
delegate.mousemoveie, delegate.mousemovecapturedie,
true true
); );
$.removeEvent( $.removeEvent(
@ -486,13 +591,13 @@
$.removeEvent( $.removeEvent(
window, window,
"mousemove", "mousemove",
delegate.mousemove, delegate.mousemovecaptured,
true true
); );
$.removeEvent( $.removeEvent(
window, window,
"mouseup", "mouseup",
delegate.mouseupwindow, delegate.mouseupcaptured,
true true
); );
} }
@ -505,11 +610,11 @@
* @private * @private
* @inner * @inner
*/ */
function triggerOthers( tracker, handler, event ) { function triggerOthers( tracker, handler, event, isTouch ) {
var otherHash; var otherHash;
for ( otherHash in ACTIVE ) { for ( otherHash in ACTIVE ) {
if ( ACTIVE.hasOwnProperty( otherHash ) && tracker.hash != otherHash ) { if ( ACTIVE.hasOwnProperty( otherHash ) && tracker.hash != otherHash ) {
handler( ACTIVE[ otherHash ], event ); handler( ACTIVE[ otherHash ], event, isTouch );
} }
} }
} }
@ -525,7 +630,10 @@
if ( tracker.focusHandler ) { if ( tracker.focusHandler ) {
propagate = tracker.focusHandler( propagate = tracker.focusHandler(
tracker, tracker,
event {
originalEvent: event,
userData: tracker.userData
}
); );
if ( propagate === false ) { if ( propagate === false ) {
$.cancelEvent( event ); $.cancelEvent( event );
@ -544,7 +652,10 @@
if ( tracker.blurHandler ) { if ( tracker.blurHandler ) {
propagate = tracker.blurHandler( propagate = tracker.blurHandler(
tracker, tracker,
event {
originalEvent: event,
userData: tracker.userData
}
); );
if ( propagate === false ) { if ( propagate === false ) {
$.cancelEvent( event ); $.cancelEvent( event );
@ -563,8 +674,13 @@
if ( tracker.keyHandler ) { if ( tracker.keyHandler ) {
propagate = tracker.keyHandler( propagate = tracker.keyHandler(
tracker, tracker,
event.keyCode ? event.keyCode : event.charCode, {
event.shiftKey position: getMouseRelative( event, tracker.element ),
keyCode: event.keyCode ? event.keyCode : event.charCode,
shift: event.shiftKey,
originalEvent: event,
userData: tracker.userData
}
); );
if ( !propagate ) { if ( !propagate ) {
$.cancelEvent( event ); $.cancelEvent( event );
@ -577,19 +693,22 @@
* @private * @private
* @inner * @inner
*/ */
function onMouseOver( tracker, event ) { function onMouseOver( tracker, event, isTouch ) {
var delegate = THIS[ tracker.hash ], var delegate = THIS[ tracker.hash ],
propagate; propagate;
isTouch = isTouch || false;
event = $.getEvent( event ); event = $.getEvent( event );
if ( !isTouch ) {
if ( $.Browser.vendor == $.BROWSERS.IE && if ( $.Browser.vendor == $.BROWSERS.IE &&
$.Browser.version < 9 && $.Browser.version < 9 &&
delegate.capturing && delegate.capturing &&
!isChild( event.srcElement, tracker.element ) ) { !isChild( event.srcElement, tracker.element ) ) {
triggerOthers( tracker, onMouseOver, event ); triggerOthers( tracker, onMouseOver, event, isTouch );
} }
var to = event.target ? var to = event.target ?
@ -603,15 +722,21 @@
isChild( tracker.element, from ) ) { isChild( tracker.element, from ) ) {
return; return;
} }
}
delegate.insideElement = true; delegate.insideElement = true;
if ( tracker.enterHandler ) { if ( tracker.enterHandler ) {
propagate = tracker.enterHandler( propagate = tracker.enterHandler(
tracker, tracker,
getMouseRelative( event, tracker.element ), {
delegate.buttonDown, position: getMouseRelative( isTouch ? event.changedTouches[ 0 ] : event, tracker.element ),
IS_BUTTON_DOWN insideElementPressed: delegate.insideElementPressed,
buttonDownAny: IS_BUTTON_DOWN,
isTouchEvent: isTouch,
originalEvent: event,
userData: tracker.userData
}
); );
if ( propagate === false ) { if ( propagate === false ) {
$.cancelEvent( event ); $.cancelEvent( event );
@ -624,18 +749,21 @@
* @private * @private
* @inner * @inner
*/ */
function onMouseOut( tracker, event ) { function onMouseOut( tracker, event, isTouch ) {
var delegate = THIS[ tracker.hash ], var delegate = THIS[ tracker.hash ],
propagate; propagate;
isTouch = isTouch || false;
event = $.getEvent( event ); event = $.getEvent( event );
if ( !isTouch ) {
if ( $.Browser.vendor == $.BROWSERS.IE && if ( $.Browser.vendor == $.BROWSERS.IE &&
$.Browser.version < 9 && $.Browser.version < 9 &&
delegate.capturing && delegate.capturing &&
!isChild( event.srcElement, tracker.element ) ) { !isChild( event.srcElement, tracker.element ) ) {
triggerOthers( tracker, onMouseOut, event ); triggerOthers( tracker, onMouseOut, event, isTouch );
} }
@ -650,15 +778,21 @@
isChild( tracker.element, to ) ) { isChild( tracker.element, to ) ) {
return; return;
} }
}
delegate.insideElement = false; delegate.insideElement = false;
if ( tracker.exitHandler ) { if ( tracker.exitHandler ) {
propagate = tracker.exitHandler( propagate = tracker.exitHandler(
tracker, tracker,
getMouseRelative( event, tracker.element ), {
delegate.buttonDown, position: getMouseRelative( isTouch ? event.changedTouches[ 0 ] : event, tracker.element ),
IS_BUTTON_DOWN insideElementPressed: delegate.insideElementPressed,
buttonDownAny: IS_BUTTON_DOWN,
isTouchEvent: isTouch,
originalEvent: event,
userData: tracker.userData
}
); );
if ( propagate === false ) { if ( propagate === false ) {
@ -672,26 +806,35 @@
* @private * @private
* @inner * @inner
*/ */
function onMouseDown( tracker, event, noCapture ) { function onMouseDown( tracker, event, noCapture, isTouch ) {
var delegate = THIS[ tracker.hash ], var delegate = THIS[ tracker.hash ],
propagate; propagate;
isTouch = isTouch || false;
event = $.getEvent(event); event = $.getEvent(event);
var eventOrTouchPoint = isTouch ? event.touches[ 0 ] : event;
if ( event.button == 2 ) { if ( event.button == 2 ) {
return; return;
} }
delegate.buttonDown = 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();
if ( tracker.pressHandler ) { if ( tracker.pressHandler ) {
propagate = tracker.pressHandler( propagate = tracker.pressHandler(
tracker, tracker,
getMouseRelative( event, tracker.element ) {
position: getMouseRelative( eventOrTouchPoint, tracker.element ),
isTouchEvent: isTouch,
originalEvent: event,
userData: tracker.userData
}
); );
if ( propagate === false ) { if ( propagate === false ) {
$.cancelEvent( event ); $.cancelEvent( event );
@ -706,7 +849,8 @@
return; return;
} }
if ( !( $.Browser.vendor == $.BROWSERS.IE && $.Browser.version < 9 ) || if ( isTouch ||
!( $.Browser.vendor == $.BROWSERS.IE && $.Browser.version < 9 ) ||
!IS_CAPTURING ) { !IS_CAPTURING ) {
captureMouse( tracker ); captureMouse( tracker );
IS_CAPTURING = true; IS_CAPTURING = true;
@ -731,10 +875,10 @@
event.changedTouches.length == 1 ) { event.changedTouches.length == 1 ) {
THIS[ tracker.hash ].lastTouch = event.touches[ 0 ]; THIS[ tracker.hash ].lastTouch = event.touches[ 0 ];
onMouseOver( tracker, event.changedTouches[ 0 ] ); onMouseOver( tracker, event, true );
// call with no capture as the onMouseMove will // call with no capture as the onMouseMoveCaptured will
// be triggered by onTouchMove // be triggered by onTouchMove
onMouseDown( tracker, event.touches[ 0 ], true ); onMouseDown( tracker, event, true, true );
} }
if ( event.touches.length == 2 ) { if ( event.touches.length == 2 ) {
@ -759,36 +903,43 @@
* @private * @private
* @inner * @inner
*/ */
function onMouseUp( tracker, event ) { function onMouseUp( tracker, event, isTouch ) {
var delegate = THIS[ tracker.hash ], var delegate = THIS[ tracker.hash ],
//were we inside the tracked element when we were pressed //were we inside the tracked element when we were pressed
insideElementPress = delegate.buttonDown, insideElementPressed = delegate.insideElementPressed,
//are we still inside the tracked element when we released //are we still inside the tracked element when we released
insideElementRelease = delegate.insideElement, insideElementReleased = delegate.insideElement,
propagate; propagate;
isTouch = isTouch || false;
event = $.getEvent(event); event = $.getEvent(event);
if ( event.button == 2 ) { if ( event.button == 2 ) {
return; return;
} }
delegate.buttonDown = false; delegate.insideElementPressed = false;
if ( tracker.releaseHandler ) { if ( tracker.releaseHandler ) {
propagate = tracker.releaseHandler( propagate = tracker.releaseHandler(
tracker, tracker,
getMouseRelative( event, tracker.element ), {
insideElementPress, position: getMouseRelative( isTouch ? event.changedTouches[ 0 ] : event, tracker.element ),
insideElementRelease insideElementPressed: insideElementPressed,
insideElementReleased: insideElementReleased,
isTouchEvent: isTouch,
originalEvent: event,
userData: tracker.userData
}
); );
if ( propagate === false ) { if ( propagate === false ) {
$.cancelEvent( event ); $.cancelEvent( event );
} }
} }
if ( insideElementPress && insideElementRelease ) { if ( insideElementPressed && insideElementReleased ) {
handleMouseClick( tracker, event ); handleMouseClick( tracker, event, isTouch );
} }
} }
@ -807,8 +958,8 @@
// call with no release, as the mouse events are // call with no release, as the mouse events are
// not registered in onTouchStart // not registered in onTouchStart
onMouseUpWindow( tracker, event.changedTouches[ 0 ], true ); onMouseUpCaptured( tracker, event, true, true );
onMouseOut( tracker, event.changedTouches[ 0 ] ); onMouseOut( tracker, event, true );
} }
if ( event.touches.length + event.changedTouches.length == 2 ) { if ( event.touches.length + event.changedTouches.length == 2 ) {
THIS[ tracker.hash ].lastPinchDelta = null; THIS[ tracker.hash ].lastPinchDelta = null;
@ -842,7 +993,7 @@
for ( i = 0; i < CAPTURING.length; i++ ) { for ( i = 0; i < CAPTURING.length; i++ ) {
othertracker = CAPTURING[ i ]; othertracker = CAPTURING[ i ];
if ( !hasMouse( othertracker ) ) { if ( !hasMouse( othertracker ) ) {
onMouseUp( othertracker, event ); onMouseUp( othertracker, event, false );
} }
} }
@ -866,9 +1017,11 @@
* @private * @private
* @inner * @inner
*/ */
function onMouseUpWindow( tracker, event, noRelease ) { function onMouseUpCaptured( tracker, event, noRelease, isTouch ) {
isTouch = isTouch || false;
if ( !THIS[ tracker.hash ].insideElement ) { if ( !THIS[ tracker.hash ].insideElement ) {
onMouseUp( tracker, event ); onMouseUp( tracker, event, isTouch );
} }
if ( noRelease ) { if ( noRelease ) {
@ -879,6 +1032,30 @@
} }
/**
* @private
* @inner
*/
function onMouseMove( tracker, event ) {
if ( tracker.moveHandler ) {
event = $.getEvent( event );
var propagate = tracker.moveHandler(
tracker,
{
position: getMouseRelative( event, tracker.element ),
isTouchEvent: false,
originalEvent: event,
userData: tracker.userData
}
);
if ( propagate === false ) {
$.cancelEvent( event );
}
}
}
/** /**
* @private * @private
* @inner * @inner
@ -894,10 +1071,12 @@
* @private * @private
* @inner * @inner
*/ */
function onMouseWheelSpin( tracker, event ) { function onMouseWheelSpin( tracker, event, isTouch ) {
var nDelta = 0, var nDelta = 0,
propagate; propagate;
isTouch = isTouch || false;
if ( !event ) { // For IE, access the global (window) event object if ( !event ) { // For IE, access the global (window) event object
event = window.event; event = window.event;
} }
@ -918,9 +1097,17 @@
if ( tracker.scrollHandler ) { if ( tracker.scrollHandler ) {
propagate = tracker.scrollHandler( propagate = tracker.scrollHandler(
tracker, tracker,
getMouseRelative( event, tracker.element ), {
nDelta, // Note: Ok to call getMouseRelative on passed event for isTouch==true since
event.shiftKey // event.pageX/event.pageY are added to the original touchmove event in
// onTouchMove().
position: getMouseRelative( event, tracker.element ),
scroll: nDelta,
shift: event.shiftKey,
isTouchEvent: isTouch,
originalEvent: event,
userData: tracker.userData
}
); );
if ( propagate === false ) { if ( propagate === false ) {
$.cancelEvent( event ); $.cancelEvent( event );
@ -933,18 +1120,22 @@
* @private * @private
* @inner * @inner
*/ */
function handleMouseClick( tracker, event ) { function handleMouseClick( tracker, event, isTouch ) {
var delegate = THIS[ tracker.hash ], var delegate = THIS[ tracker.hash ],
propagate; propagate;
isTouch = isTouch || false;
event = $.getEvent( event ); event = $.getEvent( 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;
@ -952,9 +1143,14 @@
if ( tracker.clickHandler ) { if ( tracker.clickHandler ) {
propagate = tracker.clickHandler( propagate = tracker.clickHandler(
tracker, tracker,
getMouseRelative( event, tracker.element ), {
quick, position: getMouseRelative( eventOrTouchPoint, tracker.element ),
event.shiftKey quick: quick,
shift: event.shiftKey,
isTouchEvent: isTouch,
originalEvent: event,
userData: tracker.userData
}
); );
if ( propagate === false ) { if ( propagate === false ) {
$.cancelEvent( event ); $.cancelEvent( event );
@ -967,14 +1163,17 @@
* @private * @private
* @inner * @inner
*/ */
function onMouseMove( tracker, event ) { function onMouseMoveCaptured( tracker, event, isTouch ) {
var delegate = THIS[ tracker.hash ], var delegate = THIS[ tracker.hash ],
delta, delta,
propagate, propagate,
point; point;
isTouch = isTouch || false;
event = $.getEvent(event); event = $.getEvent(event);
point = getMouseAbsolute( event ); var eventOrTouchPoint = isTouch ? event.touches[ 0 ] : event;
point = getMouseAbsolute( eventOrTouchPoint );
delta = point.minus( delegate.lastPoint ); delta = point.minus( delegate.lastPoint );
delegate.lastPoint = point; delegate.lastPoint = point;
@ -982,9 +1181,14 @@
if ( tracker.dragHandler ) { if ( tracker.dragHandler ) {
propagate = tracker.dragHandler( propagate = tracker.dragHandler(
tracker, tracker,
getMouseRelative( event, tracker.element ), {
delta, position: getMouseRelative( eventOrTouchPoint, tracker.element ),
event.shiftKey delta: delta,
shift: event.shiftKey,
isTouchEvent: isTouch,
originalEvent: event,
userData: tracker.userData
}
); );
if ( propagate === false ) { if ( propagate === false ) {
$.cancelEvent( event ); $.cancelEvent( event );
@ -1011,7 +1215,7 @@
event.changedTouches.length === 1 && event.changedTouches.length === 1 &&
THIS[ tracker.hash ].lastTouch.identifier === event.touches[ 0 ].identifier ) { THIS[ tracker.hash ].lastTouch.identifier === event.touches[ 0 ].identifier ) {
onMouseMove( tracker, event.touches[ 0 ] ); onMouseMoveCaptured( tracker, event, true );
} else if ( event.touches.length === 2 ) { } else if ( event.touches.length === 2 ) {
@ -1025,14 +1229,13 @@
if ( Math.abs( THIS[ tracker.hash ].lastPinchDelta - pinchDelta ) > 75 ) { if ( Math.abs( THIS[ tracker.hash ].lastPinchDelta - pinchDelta ) > 75 ) {
//$.console.debug( "pinch delta : " + pinchDelta + " | previous : " + THIS[ tracker.hash ].lastPinchDelta); //$.console.debug( "pinch delta : " + pinchDelta + " | previous : " + THIS[ tracker.hash ].lastPinchDelta);
onMouseWheelSpin( tracker, { // Adjust the original event enough to simulate a mouse wheel scroll
shift: false, event.shiftKey = event.shiftKey || false;
pageX: THIS[ tracker.hash ].pinchMidpoint.x, event.pageX = THIS[ tracker.hash ].pinchMidpoint.x;
pageY: THIS[ tracker.hash ].pinchMidpoint.y, event.pageY = THIS[ tracker.hash ].pinchMidpoint.y;
detail:( event.detail = ( THIS[ tracker.hash ].lastPinchDelta > pinchDelta ) ? 1 : -1;
THIS[ tracker.hash ].lastPinchDelta > pinchDelta
) ? 1 : -1 onMouseWheelSpin( tracker, event, true );
});
THIS[ tracker.hash ].lastPinchDelta = pinchDelta; THIS[ tracker.hash ].lastPinchDelta = pinchDelta;
} }
@ -1049,10 +1252,10 @@
* @private * @private
* @inner * @inner
*/ */
function onMouseMoveIE( tracker, event ) { function onMouseMoveCapturedIE( tracker, event ) {
var i; var i;
for ( i = 0; i < CAPTURING.length; i++ ) { for ( i = 0; i < CAPTURING.length; i++ ) {
onMouseMove( CAPTURING[ i ], event ); onMouseMoveCaptured( CAPTURING[ i ], event, false );
} }
$.stopEvent( event ); $.stopEvent( event );
@ -1072,7 +1275,7 @@
*/ */
function getMouseRelative( event, element ) { function getMouseRelative( event, element ) {
var mouse = $.getMousePosition( event ), var mouse = $.getMousePosition( event ),
offset = $.getElementPosition( element ); offset = $.getElementOffset( element );
return mouse.minus( offset ); return mouse.minus( offset );
} }

View File

@ -251,13 +251,13 @@ $.extend( $.Navigator.prototype, $.EventHandler.prototype, $.Viewer.prototype, {
* @inner * @inner
* @function * @function
*/ */
function onCanvasClick( tracker, position, quick, shift ) { function onCanvasClick( tracker, eventData ) {
var newBounds, var newBounds,
viewerPosition, viewerPosition,
dimensions; dimensions;
if (! this.drag) { if (! this.drag) {
if ( this.viewer.viewport ) { if ( this.viewer.viewport ) {
viewerPosition = this.viewport.deltaPointsFromPixels(position); viewerPosition = this.viewport.deltaPointsFromPixels( eventData.position );
dimensions = this.viewer.viewport.getBounds().getSize(); dimensions = this.viewer.viewport.getBounds().getSize();
newBounds = new $.Rect( newBounds = new $.Rect(
viewerPosition.x - dimensions.x/2, viewerPosition.x - dimensions.x/2,
@ -285,18 +285,18 @@ function onCanvasClick( tracker, position, quick, shift ) {
* @inner * @inner
* @function * @function
*/ */
function onCanvasDrag( tracker, position, delta, shift ) { function onCanvasDrag( tracker, eventData ) {
if ( this.viewer.viewport ) { if ( this.viewer.viewport ) {
this.drag = true; this.drag = true;
if( !this.panHorizontal ){ if( !this.panHorizontal ){
delta.x = 0; eventData.delta.x = 0;
} }
if( !this.panVertical ){ if( !this.panVertical ){
delta.y = 0; eventData.delta.y = 0;
} }
this.viewer.viewport.panBy( this.viewer.viewport.panBy(
this.viewport.deltaPointsFromPixels( this.viewport.deltaPointsFromPixels(
delta eventData.delta
) )
); );
} }
@ -308,8 +308,8 @@ function onCanvasDrag( tracker, position, delta, shift ) {
* @inner * @inner
* @function * @function
*/ */
function onCanvasRelease( tracker, position, insideElementPress, insideElementRelease ) { function onCanvasRelease( tracker, eventData ) {
if ( insideElementPress && this.viewer.viewport ) { if ( eventData.insideElementPressed && this.viewer.viewport ) {
this.viewer.viewport.applyConstraints(); this.viewer.viewport.applyConstraints();
} }
} }

View File

@ -699,6 +699,44 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
}, },
/**
* Determines the position of the upper-left corner of the element adjusted for current page and/or element scroll.
* @function
* @name OpenSeadragon.getElementOffset
* @param {Element|String} element - the element we want the position for.
* @returns {Point} - the position of the upper left corner of the element adjusted for current page and/or element scroll.
*/
getElementOffset: function( element ) {
element = $.getElement( element );
var doc = element && element.ownerDocument,
docElement,
win,
boundingRect = { top: 0, left: 0 };
if ( !doc ) {
return new $.Point();
}
docElement = doc.documentElement;
if ( typeof element.getBoundingClientRect !== typeof undefined ) {
boundingRect = element.getBoundingClientRect();
}
win = ( doc == doc.window ) ?
doc :
( doc.nodeType === 9 ) ?
doc.defaultView || doc.parentWindow :
false;
return new $.Point(
boundingRect.left + ( win.pageXOffset || docElement.scrollLeft ) - ( docElement.clientLeft || 0 ),
boundingRect.top + ( win.pageYOffset || docElement.scrollTop ) - ( docElement.clientTop || 0 )
);
},
/** /**
* Determines the height and width of the given element. * Determines the height and width of the given element.
* @function * @function

View File

@ -189,16 +189,16 @@ $.ReferenceStrip = function( options ){
element: element, element: element,
clickTimeThreshold: this.clickTimeThreshold, clickTimeThreshold: this.clickTimeThreshold,
clickDistThreshold: this.clickDistThreshold, clickDistThreshold: this.clickDistThreshold,
pressHandler: function( tracker ){ pressHandler: function ( tracker, eventData ) {
tracker.dragging = $.now(); tracker.dragging = $.now();
}, },
releaseHandler: function( tracker, position, insideElementPress, insideElementRelease ){ releaseHandler: function ( tracker, eventData ) {
var id = tracker.element.id, var id = tracker.element.id,
page = Number( id.split( '-' )[2] ), page = Number( id.split( '-' )[2] ),
now = $.now(); now = $.now();
if ( insideElementPress && if ( eventData.insideElementPressed &&
insideElementRelease && eventData.insideElementReleased &&
tracker.dragging && tracker.dragging &&
( now - tracker.dragging ) < tracker.clickTimeThreshold ) { ( now - tracker.dragging ) < tracker.clickTimeThreshold ) {
tracker.dragging = null; tracker.dragging = null;
@ -264,7 +264,7 @@ $.extend( $.ReferenceStrip.prototype, $.EventHandler.prototype, $.Viewer.prototy
this.currentPage = page; this.currentPage = page;
$.getElement( element.id + '-displayregion' ).focus(); $.getElement( element.id + '-displayregion' ).focus();
onStripEnter.call( this, this.innerTracker ); onStripEnter.call( this, this.innerTracker, {} );
} }
}, },
/** /**
@ -289,7 +289,7 @@ $.extend( $.ReferenceStrip.prototype, $.EventHandler.prototype, $.Viewer.prototy
* @inner * @inner
* @function * @function
*/ */
function onStripDrag( tracker, position, delta, shift ) { function onStripDrag( tracker, eventData ) {
var offsetLeft = Number( this.element.style.marginLeft.replace( 'px', '' ) ), var offsetLeft = Number( this.element.style.marginLeft.replace( 'px', '' ) ),
offsetTop = Number( this.element.style.marginTop.replace( 'px', '' ) ), offsetTop = Number( this.element.style.marginTop.replace( 'px', '' ) ),
@ -299,31 +299,31 @@ function onStripDrag( tracker, position, delta, shift ) {
this.dragging = true; this.dragging = true;
if ( this.element ) { if ( this.element ) {
if ( 'horizontal' == this.scroll ) { if ( 'horizontal' == this.scroll ) {
if ( -delta.x > 0 ) { if ( -eventData.delta.x > 0 ) {
//forward //forward
if ( offsetLeft > -( scrollWidth - viewerSize.x ) ) { if ( offsetLeft > -( scrollWidth - viewerSize.x ) ) {
this.element.style.marginLeft = ( offsetLeft + (delta.x * 2) ) + 'px'; this.element.style.marginLeft = ( offsetLeft + ( eventData.delta.x * 2 ) ) + 'px';
loadPanels( this, viewerSize.x, offsetLeft + (delta.x * 2) ); loadPanels( this, viewerSize.x, offsetLeft + ( eventData.delta.x * 2 ) );
} }
} else if ( -delta.x < 0 ) { } else if ( -eventData.delta.x < 0 ) {
//reverse //reverse
if ( offsetLeft < 0 ) { if ( offsetLeft < 0 ) {
this.element.style.marginLeft = ( offsetLeft + (delta.x * 2) ) + 'px'; this.element.style.marginLeft = ( offsetLeft + ( eventData.delta.x * 2 ) ) + 'px';
loadPanels( this, viewerSize.x, offsetLeft + (delta.x * 2) ); loadPanels( this, viewerSize.x, offsetLeft + ( eventData.delta.x * 2 ) );
} }
} }
} else { } else {
if ( -delta.y > 0 ) { if ( -eventData.delta.y > 0 ) {
//forward //forward
if ( offsetTop > -( scrollHeight - viewerSize.y ) ) { if ( offsetTop > -( scrollHeight - viewerSize.y ) ) {
this.element.style.marginTop = ( offsetTop + (delta.y * 2) ) + 'px'; this.element.style.marginTop = ( offsetTop + ( eventData.delta.y * 2 ) ) + 'px';
loadPanels( this, viewerSize.y, offsetTop + (delta.y * 2) ); loadPanels( this, viewerSize.y, offsetTop + ( eventData.delta.y * 2 ) );
} }
} else if ( -delta.y < 0 ) { } else if ( -eventData.delta.y < 0 ) {
//reverse //reverse
if ( offsetTop < 0 ) { if ( offsetTop < 0 ) {
this.element.style.marginTop = ( offsetTop + (delta.y * 2) ) + 'px'; this.element.style.marginTop = ( offsetTop + ( eventData.delta.y * 2 ) ) + 'px';
loadPanels( this, viewerSize.y, offsetTop + (delta.y * 2) ); loadPanels( this, viewerSize.y, offsetTop + ( eventData.delta.y * 2 ) );
} }
} }
} }
@ -339,7 +339,7 @@ function onStripDrag( tracker, position, delta, shift ) {
* @inner * @inner
* @function * @function
*/ */
function onStripScroll( tracker, position, scroll, shift ) { function onStripScroll( tracker, eventData ) {
var offsetLeft = Number( this.element.style.marginLeft.replace( 'px', '' ) ), var offsetLeft = Number( this.element.style.marginLeft.replace( 'px', '' ) ),
offsetTop = Number( this.element.style.marginTop.replace( 'px', '' ) ), offsetTop = Number( this.element.style.marginTop.replace( 'px', '' ) ),
scrollWidth = Number( this.element.style.width.replace( 'px', '' ) ), scrollWidth = Number( this.element.style.width.replace( 'px', '' ) ),
@ -347,31 +347,31 @@ function onStripScroll( tracker, position, scroll, shift ) {
viewerSize = $.getElementSize( this.viewer.canvas ); viewerSize = $.getElementSize( this.viewer.canvas );
if ( this.element ) { if ( this.element ) {
if ( 'horizontal' == this.scroll ) { if ( 'horizontal' == this.scroll ) {
if ( scroll > 0 ) { if ( eventData.scroll > 0 ) {
//forward //forward
if ( offsetLeft > -( scrollWidth - viewerSize.x ) ) { if ( offsetLeft > -( scrollWidth - viewerSize.x ) ) {
this.element.style.marginLeft = ( offsetLeft - (scroll * 60) ) + 'px'; this.element.style.marginLeft = ( offsetLeft - ( eventData.scroll * 60 ) ) + 'px';
loadPanels( this, viewerSize.x, offsetLeft - (scroll * 60) ); loadPanels( this, viewerSize.x, offsetLeft - ( eventData.scroll * 60 ) );
} }
} else if ( scroll < 0 ) { } else if ( eventData.scroll < 0 ) {
//reverse //reverse
if ( offsetLeft < 0 ) { if ( offsetLeft < 0 ) {
this.element.style.marginLeft = ( offsetLeft - (scroll * 60) ) + 'px'; this.element.style.marginLeft = ( offsetLeft - ( eventData.scroll * 60 ) ) + 'px';
loadPanels( this, viewerSize.x, offsetLeft - (scroll * 60) ); loadPanels( this, viewerSize.x, offsetLeft - ( eventData.scroll * 60 ) );
} }
} }
} else { } else {
if ( scroll < 0 ) { if ( eventData.scroll < 0 ) {
//scroll up //scroll up
if ( offsetTop > viewerSize.y - scrollHeight ) { if ( offsetTop > viewerSize.y - scrollHeight ) {
this.element.style.marginTop = ( offsetTop + (scroll * 60) ) + 'px'; this.element.style.marginTop = ( offsetTop + ( eventData.scroll * 60 ) ) + 'px';
loadPanels( this, viewerSize.y, offsetTop + (scroll * 60) ); loadPanels( this, viewerSize.y, offsetTop + ( eventData.scroll * 60 ) );
} }
} else if ( scroll > 0 ) { } else if ( eventData.scroll > 0 ) {
//scroll dowm //scroll dowm
if ( offsetTop < 0 ) { if ( offsetTop < 0 ) {
this.element.style.marginTop = ( offsetTop + (scroll * 60) ) + 'px'; this.element.style.marginTop = ( offsetTop + ( eventData.scroll * 60 ) ) + 'px';
loadPanels( this, viewerSize.y, offsetTop + (scroll * 60) ); loadPanels( this, viewerSize.y, offsetTop + ( eventData.scroll * 60 ) );
} }
} }
} }
@ -453,7 +453,7 @@ function loadPanels(strip, viewerSize, scroll){
* @inner * @inner
* @function * @function
*/ */
function onStripEnter( tracker ) { function onStripEnter( tracker, eventData ) {
//$.setElementOpacity(tracker.element, 0.8); //$.setElementOpacity(tracker.element, 0.8);
@ -480,7 +480,7 @@ function onStripEnter( tracker ) {
* @inner * @inner
* @function * @function
*/ */
function onStripExit( tracker ) { function onStripExit( tracker, eventData ) {
if ( 'horizontal' == this.scroll ) { if ( 'horizontal' == this.scroll ) {
//tracker.element.style.paddingTop = "10px"; //tracker.element.style.paddingTop = "10px";
@ -502,37 +502,37 @@ function onStripExit( tracker ) {
* @inner * @inner
* @function * @function
*/ */
function onKeyPress( tracker, keyCode, shiftKey ){ function onKeyPress( tracker, eventData ) {
//console.log( keyCode ); //console.log( eventData.keyCode );
switch( keyCode ){ switch ( eventData.keyCode ) {
case 61: //=|+ case 61: //=|+
onStripScroll.call(this, this.tracker, null, 1, null); onStripScroll.call( this, this.tracker, { position: null, scroll: 1, shift: null } );
return false; return false;
case 45: //-|_ case 45: //-|_
onStripScroll.call(this, this.tracker, null, -1, null); onStripScroll.call( this, this.tracker, { position: null, scroll: -1, shift: null } );
return false; return false;
case 48: //0|) case 48: //0|)
case 119: //w case 119: //w
case 87: //W case 87: //W
case 38: //up arrow case 38: //up arrow
onStripScroll.call(this, this.tracker, null, 1, null); onStripScroll.call( this, this.tracker, { position: null, scroll: 1, shift: null } );
return false; return false;
case 115: //s case 115: //s
case 83: //S case 83: //S
case 40: //down arrow case 40: //down arrow
onStripScroll.call(this, this.tracker, null, -1, null); onStripScroll.call( this, this.tracker, { position: null, scroll: -1, shift: null } );
return false; return false;
case 97: //a case 97: //a
case 37: //left arrow case 37: //left arrow
onStripScroll.call(this, this.tracker, null, -1, null); onStripScroll.call( this, this.tracker, { position: null, scroll: -1, shift: null } );
return false; return false;
case 100: //d case 100: //d
case 39: //right arrow case 39: //right arrow
onStripScroll.call(this, this.tracker, null, 1, null); onStripScroll.call( this, this.tracker, { position: null, scroll: 1, shift: null } );
return false; return false;
default: default:
//console.log( 'navigator keycode %s', keyCode ); //console.log( 'navigator keycode %s', eventData.keyCode );
return true; return true;
} }
} }

View File

@ -265,8 +265,8 @@ $.Viewer = function( options ) {
window.scrollTo( 0, point.y ); window.scrollTo( 0, point.y );
}, },
keyHandler: function(tracker, keyCode, shiftKey){ keyHandler: function( tracker, eventData ){
switch( keyCode ){ switch( eventData.keyCode ){
case 61://=|+ case 61://=|+
_this.viewport.zoomBy(1.1); _this.viewport.zoomBy(1.1);
_this.viewport.applyConstraints(); _this.viewport.applyConstraints();
@ -282,7 +282,7 @@ $.Viewer = function( options ) {
case 119://w case 119://w
case 87://W case 87://W
case 38://up arrow case 38://up arrow
if (shiftKey) { if ( eventData.shift ) {
_this.viewport.zoomBy(1.1); _this.viewport.zoomBy(1.1);
} else { } else {
_this.viewport.panBy(new $.Point(0, -0.05)); _this.viewport.panBy(new $.Point(0, -0.05));
@ -292,7 +292,7 @@ $.Viewer = function( options ) {
case 115://s case 115://s
case 83://S case 83://S
case 40://down arrow case 40://down arrow
if (shiftKey) { if ( eventData.shift ) {
_this.viewport.zoomBy(0.9); _this.viewport.zoomBy(0.9);
} else { } else {
_this.viewport.panBy(new $.Point(0, 0.05)); _this.viewport.panBy(new $.Point(0, 0.05));
@ -310,7 +310,7 @@ $.Viewer = function( options ) {
_this.viewport.applyConstraints(); _this.viewport.applyConstraints();
return false; return false;
default: default:
//console.log( 'navigator keycode %s', keyCode ); //console.log( 'navigator keycode %s', eventData.keyCode );
return true; return true;
} }
} }
@ -731,7 +731,7 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype,
THIS[ this.hash ].fullPage = true; THIS[ this.hash ].fullPage = true;
// mouse will be inside container now // mouse will be inside container now
$.delegate( this, onContainerEnter )(); $.delegate( this, onContainerEnter )( null, {} );
} else { } else {
@ -790,7 +790,7 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype,
THIS[ this.hash ].fullPage = false; THIS[ this.hash ].fullPage = false;
// mouse will likely be outside now // mouse will likely be outside now
$.delegate( this, onContainerExit )(); $.delegate( this, onContainerExit )( null, {} );
} }
@ -1427,37 +1427,37 @@ function onBlur(){
} }
function onCanvasClick( tracker, position, quick, shift ) { function onCanvasClick( tracker, eventData ) {
var zoomPerClick, var zoomPerClick,
factor; factor;
if ( this.viewport && quick ) { // ignore clicks where mouse moved if ( this.viewport && eventData.quick ) { // ignore clicks where mouse moved
zoomPerClick = this.zoomPerClick; zoomPerClick = this.zoomPerClick;
factor = shift ? 1.0 / zoomPerClick : zoomPerClick; factor = eventData.shift ? 1.0 / zoomPerClick : zoomPerClick;
this.viewport.zoomBy( this.viewport.zoomBy(
factor, factor,
this.viewport.pointFromPixel( position, true ) this.viewport.pointFromPixel( eventData.position, true )
); );
this.viewport.applyConstraints(); this.viewport.applyConstraints();
} }
this.raiseEvent( 'canvas-click', { this.raiseEvent( 'canvas-click', {
tracker: tracker, tracker: tracker,
position: position, position: eventData.position,
quick: quick, quick: eventData.quick,
shift: shift shift: eventData.shift
}); });
} }
function onCanvasDrag( tracker, position, delta, shift ) { function onCanvasDrag( tracker, eventData ) {
if ( this.viewport ) { if ( this.viewport ) {
if( !this.panHorizontal ){ if( !this.panHorizontal ){
delta.x = 0; eventData.delta.x = 0;
} }
if( !this.panVertical ){ if( !this.panVertical ){
delta.y = 0; eventData.delta.y = 0;
} }
this.viewport.panBy( this.viewport.panBy(
this.viewport.deltaPointsFromPixels( this.viewport.deltaPointsFromPixels(
delta.negate() eventData.delta.negate()
) )
); );
if( this.constrainDuringPan ){ if( this.constrainDuringPan ){
@ -1466,46 +1466,46 @@ function onCanvasDrag( tracker, position, delta, shift ) {
} }
this.raiseEvent( 'canvas-drag', { this.raiseEvent( 'canvas-drag', {
tracker: tracker, tracker: tracker,
position: position, position: eventData.position,
delta: delta, delta: eventData.delta,
shift: shift shift: eventData.shift
}); });
} }
function onCanvasRelease( tracker, position, insideElementPress, insideElementRelease ) { function onCanvasRelease( tracker, eventData ) {
if ( insideElementPress && this.viewport ) { if ( eventData.insideElementPressed && this.viewport ) {
this.viewport.applyConstraints(); this.viewport.applyConstraints();
} }
this.raiseEvent( 'canvas-release', { this.raiseEvent( 'canvas-release', {
tracker: tracker, tracker: tracker,
position: position, position: eventData.position,
insideElementPress: insideElementPress, insideElementPressed: eventData.insideElementPressed,
insideElementRelease: insideElementRelease insideElementReleased: eventData.insideElementReleased
}); });
} }
function onCanvasScroll( tracker, position, scroll, shift ) { function onCanvasScroll( tracker, eventData ) {
var factor; var factor;
if ( this.viewport ) { if ( this.viewport ) {
factor = Math.pow( this.zoomPerScroll, scroll ); factor = Math.pow( this.zoomPerScroll, eventData.scroll );
this.viewport.zoomBy( this.viewport.zoomBy(
factor, factor,
this.viewport.pointFromPixel( position, true ) this.viewport.pointFromPixel( eventData.position, true )
); );
this.viewport.applyConstraints(); this.viewport.applyConstraints();
} }
this.raiseEvent( 'canvas-scroll', { this.raiseEvent( 'canvas-scroll', {
tracker: tracker, tracker: tracker,
position: position, position: eventData.position,
scroll: scroll, scroll: eventData.scroll,
shift: shift shift: eventData.shift
}); });
//cancels event //cancels event
return false; return false;
} }
function onContainerExit( tracker, position, buttonDownElement, buttonDownAny ) { function onContainerExit( tracker, eventData ) {
if ( !buttonDownElement ) { if ( !eventData.insideElementPressed ) {
THIS[ this.hash ].mouseInside = false; THIS[ this.hash ].mouseInside = false;
if ( !THIS[ this.hash ].animating ) { if ( !THIS[ this.hash ].animating ) {
beginControlsAutoHide( this ); beginControlsAutoHide( this );
@ -1513,14 +1513,14 @@ function onContainerExit( tracker, position, buttonDownElement, buttonDownAny )
} }
this.raiseEvent( 'container-exit', { this.raiseEvent( 'container-exit', {
tracker: tracker, tracker: tracker,
position: position, position: eventData.position,
buttonDownElement: buttonDownElement, insideElementPressed: eventData.insideElementPressed,
buttonDownAny: buttonDownAny buttonDownAny: eventData.buttonDownAny
}); });
} }
function onContainerRelease( tracker, position, insideElementPress, insideElementRelease ) { function onContainerRelease( tracker, eventData ) {
if ( !insideElementRelease ) { if ( !eventData.insideElementReleased ) {
THIS[ this.hash ].mouseInside = false; THIS[ this.hash ].mouseInside = false;
if ( !THIS[ this.hash ].animating ) { if ( !THIS[ this.hash ].animating ) {
beginControlsAutoHide( this ); beginControlsAutoHide( this );
@ -1528,20 +1528,20 @@ function onContainerRelease( tracker, position, insideElementPress, insideElemen
} }
this.raiseEvent( 'container-release', { this.raiseEvent( 'container-release', {
tracker: tracker, tracker: tracker,
position: position, position: eventData.position,
insideElementPress: insideElementPress, insideElementPressed: eventData.insideElementPressed,
insideElementRelease: insideElementRelease insideElementReleased: eventData.insideElementReleased
}); });
} }
function onContainerEnter( tracker, position, buttonDownElement, buttonDownAny ) { function onContainerEnter( tracker, eventData ) {
THIS[ this.hash ].mouseInside = true; THIS[ this.hash ].mouseInside = true;
abortControlsAutoHide( this ); abortControlsAutoHide( this );
this.raiseEvent( 'container-enter', { this.raiseEvent( 'container-enter', {
tracker: tracker, tracker: tracker,
position: position, position: eventData.position,
buttonDownElement: buttonDownElement, insideElementPressed: eventData.insideElementPressed,
buttonDownAny: buttonDownAny buttonDownAny: eventData.buttonDownAny
}); });
} }

View File

@ -61,19 +61,49 @@
} ); } );
// ---------- // ----------
asyncTest( 'canvas-drag canvas-release canvas-click', function () { asyncTest( 'MouseTracker, EventHandler canvas-drag canvas-release canvas-click', function () {
var dragCount = 10, var $canvas = $( viewer.element ).find( '.openseadragon-canvas' ).not( '.navigator .openseadragon-canvas' ),
dragMovesHandled = 0, mouseTracker = null,
releasesHandled = 0, userData = { item1: 'Test user data', item2: Math.random() },
releasesExpected = 1; originalUserData = { item1: userData.item1, item2: userData.item2 },
dragCount = 10,
dragsHandledEventHandler = 0,
releasesHandledEventHandler = 0,
clicksHandledEventHandler = 0,
eventsHandledMouseTracker = 0,
originalEventsPassedMouseTracker = 0,
releasesExpected = 1,
clicksExpected = 1;
var openHandler = function ( eventSender, eventData ) { var onOpen = function ( eventSender, eventData ) {
viewer.removeHandler( 'open', openHandler ); viewer.removeHandler( 'open', onOpen );
viewer.addHandler( 'canvas-drag', canvasDragHandler ); viewer.addHandler( 'canvas-drag', onEventHandlerDrag );
viewer.addHandler( 'canvas-release', canvasReleaseHandler ); viewer.addHandler( 'canvas-release', onEventHandlerRelease );
viewer.addHandler( 'canvas-click', canvasClickHandler ); viewer.addHandler( 'canvas-click', onEventHandlerClick );
mouseTracker = new OpenSeadragon.MouseTracker( {
element: $canvas[0],
userData: userData,
clickTimeThreshold: OpenSeadragon.DEFAULT_SETTINGS.clickTimeThreshold,
clickDistThreshold: OpenSeadragon.DEFAULT_SETTINGS.clickDistThreshold,
focusHandler: onMouseTrackerFocus,
blurHandler: onMouseTrackerBlur,
enterHandler: onMouseTrackerEnter,
pressHandler: onMouseTrackerPress,
moveHandler: onMouseTrackerMove,
dragHandler: onMouseTrackerDrag,
releaseHandler: onMouseTrackerRelease,
clickHandler: onMouseTrackerClick,
exitHandler: onMouseTrackerExit
} ).setTracking( true );
var event = {
clientX:1,
clientY:1
};
$canvas.simulate( 'focus', event );
Util.simulateViewerClickWithDrag( { Util.simulateViewerClickWithDrag( {
viewer: viewer, viewer: viewer,
widthFactor: 0.25, widthFactor: 0.25,
@ -82,27 +112,80 @@
dragDx: 1, dragDx: 1,
dragDy: 1 dragDy: 1
} ); } );
$canvas.simulate( 'blur', event );
}; };
var canvasDragHandler = function ( eventSender, eventData ) { var onEventHandlerDrag = function ( eventSender, eventData ) {
dragMovesHandled++; dragsHandledEventHandler++;
}; };
var canvasReleaseHandler = function ( eventSender, eventData ) { var onEventHandlerRelease = function ( eventSender, eventData ) {
releasesHandled++; releasesHandledEventHandler++;
}; };
var canvasClickHandler = function ( eventSender, eventData ) { var onEventHandlerClick = function ( eventSender, eventData ) {
viewer.removeHandler( 'canvas-drag', canvasDragHandler ); clicksHandledEventHandler++;
viewer.removeHandler( 'canvas-release', canvasReleaseHandler ); };
viewer.removeHandler( 'canvas-click', canvasClickHandler );
equal( dragMovesHandled, dragCount, "'canvas-drag' event count matches 'mousemove' event count (" + dragCount + ")" ); var checkOriginalEventReceived = function ( eventData ) {
equal( releasesHandled, releasesExpected, "'canvas-release' event count matches expected (" + releasesExpected + ")" ); eventsHandledMouseTracker++;
if ( eventData && eventData.originalEvent ) {
originalEventsPassedMouseTracker++;
}
};
var onMouseTrackerFocus = function ( tracker, eventData ) {
checkOriginalEventReceived( eventData );
};
var onMouseTrackerBlur = function ( tracker, eventData ) {
checkOriginalEventReceived( eventData );
};
var onMouseTrackerEnter = function ( tracker, eventData ) {
checkOriginalEventReceived( eventData );
};
var onMouseTrackerPress = function ( tracker, eventData ) {
checkOriginalEventReceived( eventData );
};
var onMouseTrackerMove = function ( tracker, eventData ) {
checkOriginalEventReceived( eventData );
};
var onMouseTrackerDrag = function ( tracker, eventData ) {
checkOriginalEventReceived( eventData );
};
var onMouseTrackerRelease = function ( tracker, eventData ) {
checkOriginalEventReceived( eventData );
};
var onMouseTrackerClick = function ( tracker, eventData ) {
checkOriginalEventReceived( eventData );
};
var onMouseTrackerExit = function ( tracker, eventData ) {
checkOriginalEventReceived( eventData );
mouseTracker.destroy();
viewer.removeHandler( 'canvas-drag', onEventHandlerDrag );
viewer.removeHandler( 'canvas-release', onEventHandlerRelease );
viewer.removeHandler( 'canvas-click', onEventHandlerClick );
equal( dragsHandledEventHandler, dragCount, "'canvas-drag' event count matches 'mousemove' event count (" + dragCount + ")" );
equal( releasesHandledEventHandler, releasesExpected, "'canvas-release' event count matches expected (" + releasesExpected + ")" );
equal( clicksHandledEventHandler, releasesExpected, "'canvas-click' event count matches expected (" + releasesExpected + ")" );
equal( originalEventsPassedMouseTracker, eventsHandledMouseTracker, "Original event received count matches expected (" + eventsHandledMouseTracker + ")" );
deepEqual( eventData.userData, originalUserData, 'MouseTracker userData was untouched' );
viewer.close(); viewer.close();
start(); start();
}; };
viewer.addHandler( 'open', openHandler ); viewer.addHandler( 'open', onOpen );
viewer.open( '/test/data/testpattern.dzi' ); viewer.open( '/test/data/testpattern.dzi' );
} ); } );

View File

@ -46,7 +46,8 @@
.simulate( "mousemove", event ); .simulate( "mousemove", event );
} }
$canvas $canvas
.simulate( 'mouseup', event ); .simulate( 'mouseup', event )
.simulate( 'mouseout', event );
}, },
initializeTestDOM: function () { initializeTestDOM: function () {