From d574700b3d11fdc766c1ce413677d2db7ededc37 Mon Sep 17 00:00:00 2001 From: Mark Salsbery Date: Thu, 10 Oct 2013 17:00:15 -0700 Subject: [PATCH] Event Handler Signatures Changed to 'fn(event)' All event handler signatures changed to 'fn(event)' eventSource property added to the event object passed Redundant event source properties removed ('button' and 'viewer' Documentation updated in MouseTracker changelog.txt updated --- changelog.txt | 8 +- src/button.js | 54 +++++++------- src/buttongroup.js | 14 ++-- src/drawer.js | 14 +--- src/eventsource.js | 3 +- src/mousetracker.js | 170 +++++++++++++++++++++--------------------- src/navigator.js | 20 ++--- src/referencestrip.js | 118 ++++++++++++++--------------- src/tilesource.js | 4 +- src/viewer.js | 132 ++++++++++++++++---------------- src/viewport.js | 18 ++--- test/basic.js | 10 +-- test/events.js | 74 +++++++++--------- test/formats.js | 6 +- test/navigator.js | 12 +-- 15 files changed, 325 insertions(+), 332 deletions(-) diff --git a/changelog.txt b/changelog.txt index fc9e3ed6..22e3a06c 100644 --- a/changelog.txt +++ b/changelog.txt @@ -3,8 +3,12 @@ OPENSEADRAGON CHANGELOG 1.0.0: (in progress) +* BREAKING CHANGE: All EventSource and MouseTracker event handler method signatures changed to 'handlerMethod(event)' where event == { eventSource, userData, ... } (#251) (Also fixes #23, #224, #239) +* The new eventSource property in the event object replaces the old eventSource parameter that was passed to handler methods. +* Where the event object duplicated the eventSource value, those properties have been removed. This effects the following events: +* All Button events - 'button' property removed +* All Viewer (Viewer, Drawer, Viewport) events - 'viewer' property removed * BREAKING CHANGE: Renamed EventHandler to EventSource (#225) -* BREAKING CHANGE: MouseTracker event handler method signatures changed to 'handlerMethod( tracker, eventData)' (#23) * BREAKING CHANGE: Event names changed for consistency: changed to lower case, compound names hyphenated, and "on" prefixes removed (#226): * Viewer "animationstart" changed to "animation-start" * Viewer "animationfinish" changed to "animation-finish" @@ -15,8 +19,6 @@ OPENSEADRAGON CHANGELOG * Button "onExit" changed to "exit" * Button "onFocus" changed to "focus" * Button "onBlur" changed to "blur" -* BREAKING CHANGE: Button event handler method signatures changed to 'handlerMethod( eventSource, eventData)' where eventData == { button } (#224) -* BREAKING CHANGE: TileSource 'ready' event handler signature changed to 'handlerMethod( eventSource, eventData)' where eventData == { tileSource } (#239) * MouseTracker now passes the original event objects to its handler methods (#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) diff --git a/src/button.js b/src/button.js index cc7febb7..e32ca35a 100644 --- a/src/button.js +++ b/src/button.js @@ -175,59 +175,59 @@ $.Button = function( options ) { clickTimeThreshold: this.clickTimeThreshold, clickDistThreshold: this.clickDistThreshold, - enterHandler: function( tracker, eventData ) { - if ( eventData.insideElementPressed ) { + enterHandler: function( event ) { + if ( event.insideElementPressed ) { inTo( _this, $.ButtonState.DOWN ); - _this.raiseEvent( "enter", { button: _this } ); - } else if ( !eventData.buttonDownAny ) { + _this.raiseEvent( "enter", {} ); + } else if ( !event.buttonDownAny ) { inTo( _this, $.ButtonState.HOVER ); } }, - focusHandler: function ( tracker, eventData ) { - this.enterHandler( tracker, eventData ); - _this.raiseEvent( "focus", { button: _this } ); + focusHandler: function ( event ) { + this.enterHandler( event ); + _this.raiseEvent( "focus", {} ); }, - exitHandler: function( tracker, eventData ) { + exitHandler: function( event ) { outTo( _this, $.ButtonState.GROUP ); - if ( eventData.insideElementPressed ) { - _this.raiseEvent( "exit", { button: _this } ); + if ( event.insideElementPressed ) { + _this.raiseEvent( "exit", {} ); } }, - blurHandler: function ( tracker, eventData ) { - this.exitHandler( tracker, eventData ); - _this.raiseEvent( "blur", { button: _this } ); + blurHandler: function ( event ) { + this.exitHandler( event ); + _this.raiseEvent( "blur", {} ); }, - pressHandler: function ( tracker, eventData ) { + pressHandler: function ( event ) { inTo( _this, $.ButtonState.DOWN ); - _this.raiseEvent( "press", { button: _this } ); + _this.raiseEvent( "press", {} ); }, - releaseHandler: function( tracker, eventData ) { - if ( eventData.insideElementPressed && eventData.insideElementReleased ) { + releaseHandler: function( event ) { + if ( event.insideElementPressed && event.insideElementReleased ) { outTo( _this, $.ButtonState.HOVER ); - _this.raiseEvent( "release", { button: _this } ); - } else if ( eventData.insideElementPressed ) { + _this.raiseEvent( "release", {} ); + } else if ( event.insideElementPressed ) { outTo( _this, $.ButtonState.GROUP ); } else { inTo( _this, $.ButtonState.HOVER ); } }, - clickHandler: function( tracker, eventData ) { - if ( eventData.quick ) { - _this.raiseEvent("click", { button: _this }); + clickHandler: function( event ) { + if ( event.quick ) { + _this.raiseEvent("click", {}); } }, - keyHandler: function( tracker, eventData ){ - //console.log( "%s : handling key %s!", _this.tooltip, eventData.keyCode); - if( 13 === eventData.keyCode ){ - _this.raiseEvent( "click", { button: _this } ); - _this.raiseEvent( "release", { button: _this } ); + keyHandler: function( event ){ + //console.log( "%s : handling key %s!", _this.tooltip, event.keyCode); + if( 13 === event.keyCode ){ + _this.raiseEvent( "click", {} ); + _this.raiseEvent( "release", {} ); return false; } return true; diff --git a/src/buttongroup.js b/src/buttongroup.js index 5adaf09e..e6b51091 100644 --- a/src/buttongroup.js +++ b/src/buttongroup.js @@ -85,23 +85,23 @@ $.ButtonGroup = function( options ) { element: this.element, clickTimeThreshold: this.clickTimeThreshold, clickDistThreshold: this.clickDistThreshold, - enterHandler: function ( tracker, eventData ) { + enterHandler: function ( event ) { var i; for ( i = 0; i < _this.buttons.length; i++ ) { _this.buttons[ i ].notifyGroupEnter(); } }, - exitHandler: function ( tracker, eventData ) { + exitHandler: function ( event ) { var i; - if ( !eventData.insideElementPressed ) { + if ( !event.insideElementPressed ) { for ( i = 0; i < _this.buttons.length; i++ ) { _this.buttons[ i ].notifyGroupExit(); } } }, - releaseHandler: function ( tracker, eventData ) { + releaseHandler: function ( event ) { var i; - if ( !eventData.insideElementReleased ) { + if ( !event.insideElementReleased ) { for ( i = 0; i < _this.buttons.length; i++ ) { _this.buttons[ i ].notifyGroupExit(); } @@ -119,7 +119,7 @@ $.ButtonGroup.prototype = { * @name OpenSeadragon.ButtonGroup.prototype.emulateEnter */ emulateEnter: function() { - this.tracker.enterHandler( this.tracker, {} ); + this.tracker.enterHandler( { eventSource: this.tracker } ); }, /** @@ -129,7 +129,7 @@ $.ButtonGroup.prototype = { * @name OpenSeadragon.ButtonGroup.prototype.emulateExit */ emulateExit: function() { - this.tracker.exitHandler( this.tracker, {} ); + this.tracker.exitHandler( { eventSource: this.tracker } ); } }; diff --git a/src/drawer.js b/src/drawer.js index de94356c..809d9176 100644 --- a/src/drawer.js +++ b/src/drawer.js @@ -205,7 +205,6 @@ $.Drawer.prototype = { this.updateAgain = true; if( this.viewer ){ this.viewer.raiseEvent( 'add-overlay', { - viewer: this.viewer, element: element, location: options.location, placement: options.placement @@ -237,7 +236,6 @@ $.Drawer.prototype = { } if( this.viewer ){ this.viewer.raiseEvent( 'update-overlay', { - viewer: this.viewer, element: element, location: location, placement: placement @@ -267,7 +265,6 @@ $.Drawer.prototype = { } if( this.viewer ){ this.viewer.raiseEvent( 'remove-overlay', { - viewer: this.viewer, element: element }); } @@ -286,9 +283,7 @@ $.Drawer.prototype = { this.updateAgain = true; } if( this.viewer ){ - this.viewer.raiseEvent( 'clear-overlay', { - viewer: this.viewer - }); + this.viewer.raiseEvent( 'clear-overlay', {} ); } return this; }, @@ -481,9 +476,7 @@ function updateViewport( drawer ) { drawer.updateAgain = false; if( drawer.viewer ){ - drawer.viewer.raiseEvent( 'update-viewport', { - viewer: drawer.viewer - }); + drawer.viewer.raiseEvent( 'update-viewport', {} ); } var tile, @@ -658,7 +651,6 @@ function updateLevel( drawer, haveDrawn, drawLevel, level, levelOpacity, levelVi if( drawer.viewer ){ drawer.viewer.raiseEvent( 'update-level', { - viewer: drawer.viewer, havedrawn: haveDrawn, level: level, opacity: levelOpacity, @@ -722,7 +714,6 @@ function updateTile( drawer, drawLevel, haveDrawn, x, y, level, levelOpacity, le if( drawer.viewer ){ drawer.viewer.raiseEvent( 'update-tile', { - viewer: drawer.viewer, tile: tile }); } @@ -1236,7 +1227,6 @@ function drawTiles( drawer, lastDrawn ){ if( drawer.viewer ){ drawer.viewer.raiseEvent( 'tile-drawn', { - viewer: drawer.viewer, tile: tile }); } diff --git a/src/eventsource.js b/src/eventsource.js index c5289777..4349c197 100644 --- a/src/eventsource.js +++ b/src/eventsource.js @@ -121,8 +121,9 @@ $.EventSource.prototype = { length = events.length; for ( i = 0; i < length; i++ ) { if ( events[ i ] ) { + args.eventSource = source; args.userData = events[ i ].userData; - events[ i ].handler( source, args ); + events[ i ].handler( args ); } } }; diff --git a/src/mousetracker.js b/src/mousetracker.js index 51349912..e0b9e931 100644 --- a/src/mousetracker.js +++ b/src/mousetracker.js @@ -222,21 +222,21 @@ * Implement or assign implmentation to these handlers during or after * calling the constructor. * @function - * @param {OpenSeadragon.MouseTracker} tracker + * @param {Object} event + * @param {OpenSeadragon.MouseTracker} event.eventSource * A reference to the tracker instance. - * @param {Object} eventData - * @param {OpenSeadragon.Point} eventData.position + * @param {OpenSeadragon.Point} event.position * The position of the event relative to the tracked element. - * @param {Boolean} eventData.insideElementPressed + * @param {Boolean} event.insideElementPressed * True if the left mouse button is currently being pressed and was * initiated inside the tracked element, otherwise false. - * @param {Boolean} eventData.buttonDownAny + * @param {Boolean} event.buttonDownAny * Was the button down anywhere in the screen during the event. - * @param {Boolean} eventData.isTouchEvent + * @param {Boolean} event.isTouchEvent * True if the original event is a touch event, otherwise false. - * @param {Object} eventData.originalEvent + * @param {Object} event.originalEvent * The original event object. - * @param {Object} eventData.userData + * @param {Object} event.userData * Arbitrary user-defined object. */ enterHandler: function () { }, @@ -245,21 +245,21 @@ * Implement or assign implmentation to these handlers during or after * calling the constructor. * @function - * @param {OpenSeadragon.MouseTracker} tracker + * @param {Object} event + * @param {OpenSeadragon.MouseTracker} event.eventSource * A reference to the tracker instance. - * @param {Object} eventData - * @param {OpenSeadragon.Point} eventData.position + * @param {OpenSeadragon.Point} event.position * The position of the event relative to the tracked element. - * @param {Boolean} eventData.insideElementPressed + * @param {Boolean} event.insideElementPressed * True if the left mouse button is currently being pressed and was * initiated inside the tracked element, otherwise false. - * @param {Boolean} eventData.buttonDownAny + * @param {Boolean} event.buttonDownAny * Was the button down anywhere in the screen during the event. - * @param {Boolean} eventData.isTouchEvent + * @param {Boolean} event.isTouchEvent * True if the original event is a touch event, otherwise false. - * @param {Object} eventData.originalEvent + * @param {Object} event.originalEvent * The original event object. - * @param {Object} eventData.userData + * @param {Object} event.userData * Arbitrary user-defined object. */ exitHandler: function () { }, @@ -268,16 +268,16 @@ * Implement or assign implmentation to these handlers during or after * calling the constructor. * @function - * @param {OpenSeadragon.MouseTracker} tracker + * @param {Object} event + * @param {OpenSeadragon.MouseTracker} event.eventSource * A reference to the tracker instance. - * @param {Object} eventData - * @param {OpenSeadragon.Point} eventData.position + * @param {OpenSeadragon.Point} event.position * The position of the event relative to the tracked element. - * @param {Boolean} eventData.isTouchEvent + * @param {Boolean} event.isTouchEvent * True if the original event is a touch event, otherwise false. - * @param {Object} eventData.originalEvent + * @param {Object} event.originalEvent * The original event object. - * @param {Object} eventData.userData + * @param {Object} event.userData * Arbitrary user-defined object. */ pressHandler: function () { }, @@ -286,21 +286,21 @@ * Implement or assign implmentation to these handlers during or after * calling the constructor. * @function - * @param {OpenSeadragon.MouseTracker} tracker + * @param {Object} event + * @param {OpenSeadragon.MouseTracker} event.eventSource * A reference to the tracker instance. - * @param {Object} eventData - * @param {OpenSeadragon.Point} eventData.position + * @param {OpenSeadragon.Point} event.position * The position of the event relative to the tracked element. - * @param {Boolean} eventData.insideElementPressed + * @param {Boolean} event.insideElementPressed * True if the left mouse button is currently being pressed and was * initiated inside the tracked element, otherwise false. - * @param {Boolean} eventData.insideElementReleased + * @param {Boolean} event.insideElementReleased * True if the cursor still inside the tracked element when the button was released. - * @param {Boolean} eventData.isTouchEvent + * @param {Boolean} event.isTouchEvent * True if the original event is a touch event, otherwise false. - * @param {Object} eventData.originalEvent + * @param {Object} event.originalEvent * The original event object. - * @param {Object} eventData.userData + * @param {Object} event.userData * Arbitrary user-defined object. */ releaseHandler: function () { }, @@ -309,16 +309,16 @@ * Implement or assign implmentation to these handlers during or after * calling the constructor. * @function - * @param {OpenSeadragon.MouseTracker} tracker + * @param {Object} event + * @param {OpenSeadragon.MouseTracker} event.eventSource * A reference to the tracker instance. - * @param {Object} eventData - * @param {OpenSeadragon.Point} eventData.position + * @param {OpenSeadragon.Point} event.position * The position of the event relative to the tracked element. - * @param {Boolean} eventData.isTouchEvent + * @param {Boolean} event.isTouchEvent * True if the original event is a touch event, otherwise false. - * @param {Object} eventData.originalEvent + * @param {Object} event.originalEvent * The original event object. - * @param {Object} eventData.userData + * @param {Object} event.userData * Arbitrary user-defined object. */ moveHandler: function () { }, @@ -327,20 +327,20 @@ * Implement or assign implmentation to these handlers during or after * calling the constructor. * @function - * @param {OpenSeadragon.MouseTracker} tracker + * @param {Object} event + * @param {OpenSeadragon.MouseTracker} event.eventSource * A reference to the tracker instance. - * @param {Object} eventData - * @param {OpenSeadragon.Point} eventData.position + * @param {OpenSeadragon.Point} event.position * The position of the event relative to the tracked element. - * @param {Number} eventData.scroll + * @param {Number} event.scroll * The scroll delta for the event. - * @param {Boolean} eventData.shift + * @param {Boolean} event.shift * True if the shift key was pressed during this event. - * @param {Boolean} eventData.isTouchEvent + * @param {Boolean} event.isTouchEvent * True if the original event is a touch event, otherwise false. - * @param {Object} eventData.originalEvent + * @param {Object} event.originalEvent * The original event object. - * @param {Object} eventData.userData + * @param {Object} event.userData * Arbitrary user-defined object. */ scrollHandler: function () { }, @@ -349,20 +349,20 @@ * Implement or assign implmentation to these handlers during or after * calling the constructor. * @function - * @param {OpenSeadragon.MouseTracker} tracker + * @param {Object} event + * @param {OpenSeadragon.MouseTracker} event.eventSource * A reference to the tracker instance. - * @param {Object} eventData - * @param {OpenSeadragon.Point} eventData.position + * @param {OpenSeadragon.Point} event.position * The position of the event relative to the tracked element. - * @param {Number} eventData.quick + * @param {Number} event.quick * True only if the clickDistThreshold and clickDeltaThreshold are both pased. Useful for ignoring events. - * @param {Boolean} eventData.shift + * @param {Boolean} event.shift * True if the shift key was pressed during this event. - * @param {Boolean} eventData.isTouchEvent + * @param {Boolean} event.isTouchEvent * True if the original event is a touch event, otherwise false. - * @param {Object} eventData.originalEvent + * @param {Object} event.originalEvent * The original event object. - * @param {Object} eventData.userData + * @param {Object} event.userData * Arbitrary user-defined object. */ clickHandler: function () { }, @@ -371,20 +371,20 @@ * Implement or assign implmentation to these handlers during or after * calling the constructor. * @function - * @param {OpenSeadragon.MouseTracker} tracker + * @param {Object} event + * @param {OpenSeadragon.MouseTracker} event.eventSource * A reference to the tracker instance. - * @param {Object} eventData - * @param {OpenSeadragon.Point} eventData.position + * @param {OpenSeadragon.Point} event.position * The position of the event relative to the tracked element. - * @param {OpenSeadragon.Point} eventData.delta + * @param {OpenSeadragon.Point} event.delta * The x,y components of the difference between start drag and end drag. Usefule for ignoring or weighting the events. - * @param {Boolean} eventData.shift + * @param {Boolean} event.shift * True if the shift key was pressed during this event. - * @param {Boolean} eventData.isTouchEvent + * @param {Boolean} event.isTouchEvent * True if the original event is a touch event, otherwise false. - * @param {Object} eventData.originalEvent + * @param {Object} event.originalEvent * The original event object. - * @param {Object} eventData.userData + * @param {Object} event.userData * Arbitrary user-defined object. */ dragHandler: function () { }, @@ -393,16 +393,16 @@ * Implement or assign implmentation to these handlers during or after * calling the constructor. * @function - * @param {OpenSeadragon.MouseTracker} tracker + * @param {Object} event + * @param {OpenSeadragon.MouseTracker} event.eventSource * A reference to the tracker instance. - * @param {Object} eventData - * @param {Number} eventData.keyCode + * @param {Number} event.keyCode * The key code that was pressed. - * @param {Boolean} eventData.shift + * @param {Boolean} event.shift * True if the shift key was pressed during this event. - * @param {Object} eventData.originalEvent + * @param {Object} event.originalEvent * The original event object. - * @param {Object} eventData.userData + * @param {Object} event.userData * Arbitrary user-defined object. */ keyHandler: function () { }, @@ -411,12 +411,12 @@ * Implement or assign implmentation to these handlers during or after * calling the constructor. * @function - * @param {OpenSeadragon.MouseTracker} tracker + * @param {Object} event + * @param {OpenSeadragon.MouseTracker} event.eventSource * A reference to the tracker instance. - * @param {Object} eventData - * @param {Object} eventData.originalEvent + * @param {Object} event.originalEvent * The original event object. - * @param {Object} eventData.userData + * @param {Object} event.userData * Arbitrary user-defined object. */ focusHandler: function () { }, @@ -425,12 +425,12 @@ * Implement or assign implmentation to these handlers during or after * calling the constructor. * @function - * @param {OpenSeadragon.MouseTracker} tracker + * @param {Object} event + * @param {OpenSeadragon.MouseTracker} event.eventSource * A reference to the tracker instance. - * @param {Object} eventData - * @param {Object} eventData.originalEvent + * @param {Object} event.originalEvent * The original event object. - * @param {Object} eventData.userData + * @param {Object} event.userData * Arbitrary user-defined object. */ blurHandler: function () { } @@ -629,8 +629,8 @@ var propagate; if ( tracker.focusHandler ) { propagate = tracker.focusHandler( - tracker, { + eventSource: tracker, originalEvent: event, userData: tracker.userData } @@ -651,8 +651,8 @@ var propagate; if ( tracker.blurHandler ) { propagate = tracker.blurHandler( - tracker, { + eventSource: tracker, originalEvent: event, userData: tracker.userData } @@ -673,8 +673,8 @@ var propagate; if ( tracker.keyHandler ) { propagate = tracker.keyHandler( - tracker, { + eventSource: tracker, position: getMouseRelative( event, tracker.element ), keyCode: event.keyCode ? event.keyCode : event.charCode, shift: event.shiftKey, @@ -728,8 +728,8 @@ if ( tracker.enterHandler ) { propagate = tracker.enterHandler( - tracker, { + eventSource: tracker, position: getMouseRelative( isTouch ? event.changedTouches[ 0 ] : event, tracker.element ), insideElementPressed: delegate.insideElementPressed, buttonDownAny: IS_BUTTON_DOWN, @@ -784,8 +784,8 @@ if ( tracker.exitHandler ) { propagate = tracker.exitHandler( - tracker, { + eventSource: tracker, position: getMouseRelative( isTouch ? event.changedTouches[ 0 ] : event, tracker.element ), insideElementPressed: delegate.insideElementPressed, buttonDownAny: IS_BUTTON_DOWN, @@ -828,8 +828,8 @@ if ( tracker.pressHandler ) { propagate = tracker.pressHandler( - tracker, { + eventSource: tracker, position: getMouseRelative( eventOrTouchPoint, tracker.element ), isTouchEvent: isTouch, originalEvent: event, @@ -923,8 +923,8 @@ if ( tracker.releaseHandler ) { propagate = tracker.releaseHandler( - tracker, { + eventSource: tracker, position: getMouseRelative( isTouch ? event.changedTouches[ 0 ] : event, tracker.element ), insideElementPressed: insideElementPressed, insideElementReleased: insideElementReleased, @@ -1041,8 +1041,8 @@ event = $.getEvent( event ); var propagate = tracker.moveHandler( - tracker, { + eventSource: tracker, position: getMouseRelative( event, tracker.element ), isTouchEvent: false, originalEvent: event, @@ -1096,8 +1096,8 @@ if ( tracker.scrollHandler ) { propagate = tracker.scrollHandler( - tracker, { + eventSource: tracker, // Note: Ok to call getMouseRelative on passed event for isTouch==true since // event.pageX/event.pageY are added to the original touchmove event in // onTouchMove(). @@ -1142,8 +1142,8 @@ if ( tracker.clickHandler ) { propagate = tracker.clickHandler( - tracker, { + eventSource: tracker, position: getMouseRelative( eventOrTouchPoint, tracker.element ), quick: quick, shift: event.shiftKey, @@ -1180,8 +1180,8 @@ if ( tracker.dragHandler ) { propagate = tracker.dragHandler( - tracker, { + eventSource: tracker, position: getMouseRelative( eventOrTouchPoint, tracker.element ), delta: delta, shift: event.shiftKey, diff --git a/src/navigator.js b/src/navigator.js index 77119d0e..8c8d344c 100644 --- a/src/navigator.js +++ b/src/navigator.js @@ -251,13 +251,13 @@ $.extend( $.Navigator.prototype, $.EventSource.prototype, $.Viewer.prototype, { * @inner * @function */ -function onCanvasClick( tracker, eventData ) { +function onCanvasClick( event ) { var newBounds, viewerPosition, dimensions; if (! this.drag) { if ( this.viewer.viewport ) { - viewerPosition = this.viewport.deltaPointsFromPixels( eventData.position ); + viewerPosition = this.viewport.deltaPointsFromPixels( event.position ); dimensions = this.viewer.viewport.getBounds().getSize(); newBounds = new $.Rect( viewerPosition.x - dimensions.x/2, @@ -285,18 +285,18 @@ function onCanvasClick( tracker, eventData ) { * @inner * @function */ -function onCanvasDrag( tracker, eventData ) { +function onCanvasDrag( event ) { if ( this.viewer.viewport ) { this.drag = true; if( !this.panHorizontal ){ - eventData.delta.x = 0; + event.delta.x = 0; } if( !this.panVertical ){ - eventData.delta.y = 0; + event.delta.y = 0; } this.viewer.viewport.panBy( this.viewport.deltaPointsFromPixels( - eventData.delta + event.delta ) ); } @@ -308,8 +308,8 @@ function onCanvasDrag( tracker, eventData ) { * @inner * @function */ -function onCanvasRelease( tracker, eventData ) { - if ( eventData.insideElementPressed && this.viewer.viewport ) { +function onCanvasRelease( event ) { + if ( event.insideElementPressed && this.viewer.viewport ) { this.viewer.viewport.applyConstraints(); } } @@ -320,10 +320,10 @@ function onCanvasRelease( tracker, eventData ) { * @inner * @function */ -function onCanvasScroll( tracker, position, scroll, shift ) { +function onCanvasScroll( event ) { var factor; if ( this.viewer.viewport ) { - factor = Math.pow( this.zoomPerScroll, scroll ); + factor = Math.pow( this.zoomPerScroll, event.scroll ); this.viewer.viewport.zoomBy( factor, this.viewport.getCenter() diff --git a/src/referencestrip.js b/src/referencestrip.js index f821d2e3..704aeb98 100644 --- a/src/referencestrip.js +++ b/src/referencestrip.js @@ -189,19 +189,19 @@ $.ReferenceStrip = function ( options ) { element: element, clickTimeThreshold: this.clickTimeThreshold, clickDistThreshold: this.clickDistThreshold, - pressHandler: function ( tracker, eventData ) { - tracker.dragging = $.now(); + pressHandler: function ( event ) { + event.eventSource.dragging = $.now(); }, - releaseHandler: function ( tracker, eventData ) { - var id = tracker.element.id, + releaseHandler: function ( event ) { + var id = event.eventSource.element.id, page = Number( id.split( '-' )[2] ), now = $.now(); - if ( eventData.insideElementPressed && - eventData.insideElementReleased && - tracker.dragging && - ( now - tracker.dragging ) < tracker.clickTimeThreshold ) { - tracker.dragging = null; + if ( event.insideElementPressed && + event.insideElementReleased && + event.eventSource.dragging && + ( now - event.eventSource.dragging ) < event.eventSource.clickTimeThreshold ) { + event.eventSource.dragging = null; viewer.goToPage( page ); } } @@ -264,7 +264,7 @@ $.extend( $.ReferenceStrip.prototype, $.EventSource.prototype, $.Viewer.prototyp this.currentPage = page; $.getElement( element.id + '-displayregion' ).focus(); - onStripEnter.call( this, this.innerTracker, {} ); + onStripEnter.call( this, { eventSource: this.innerTracker } ); } }, /** @@ -289,7 +289,7 @@ $.extend( $.ReferenceStrip.prototype, $.EventSource.prototype, $.Viewer.prototyp * @inner * @function */ -function onStripDrag( tracker, eventData ) { +function onStripDrag( event ) { var offsetLeft = Number( this.element.style.marginLeft.replace( 'px', '' ) ), offsetTop = Number( this.element.style.marginTop.replace( 'px', '' ) ), @@ -299,31 +299,31 @@ function onStripDrag( tracker, eventData ) { this.dragging = true; if ( this.element ) { if ( 'horizontal' == this.scroll ) { - if ( -eventData.delta.x > 0 ) { + if ( -event.delta.x > 0 ) { //forward if ( offsetLeft > -( scrollWidth - viewerSize.x ) ) { - this.element.style.marginLeft = ( offsetLeft + ( eventData.delta.x * 2 ) ) + 'px'; - loadPanels( this, viewerSize.x, offsetLeft + ( eventData.delta.x * 2 ) ); + this.element.style.marginLeft = ( offsetLeft + ( event.delta.x * 2 ) ) + 'px'; + loadPanels( this, viewerSize.x, offsetLeft + ( event.delta.x * 2 ) ); } - } else if ( -eventData.delta.x < 0 ) { + } else if ( -event.delta.x < 0 ) { //reverse if ( offsetLeft < 0 ) { - this.element.style.marginLeft = ( offsetLeft + ( eventData.delta.x * 2 ) ) + 'px'; - loadPanels( this, viewerSize.x, offsetLeft + ( eventData.delta.x * 2 ) ); + this.element.style.marginLeft = ( offsetLeft + ( event.delta.x * 2 ) ) + 'px'; + loadPanels( this, viewerSize.x, offsetLeft + ( event.delta.x * 2 ) ); } } } else { - if ( -eventData.delta.y > 0 ) { + if ( -event.delta.y > 0 ) { //forward if ( offsetTop > -( scrollHeight - viewerSize.y ) ) { - this.element.style.marginTop = ( offsetTop + ( eventData.delta.y * 2 ) ) + 'px'; - loadPanels( this, viewerSize.y, offsetTop + ( eventData.delta.y * 2 ) ); + this.element.style.marginTop = ( offsetTop + ( event.delta.y * 2 ) ) + 'px'; + loadPanels( this, viewerSize.y, offsetTop + ( event.delta.y * 2 ) ); } - } else if ( -eventData.delta.y < 0 ) { + } else if ( -event.delta.y < 0 ) { //reverse if ( offsetTop < 0 ) { - this.element.style.marginTop = ( offsetTop + ( eventData.delta.y * 2 ) ) + 'px'; - loadPanels( this, viewerSize.y, offsetTop + ( eventData.delta.y * 2 ) ); + this.element.style.marginTop = ( offsetTop + ( event.delta.y * 2 ) ) + 'px'; + loadPanels( this, viewerSize.y, offsetTop + ( event.delta.y * 2 ) ); } } } @@ -339,7 +339,7 @@ function onStripDrag( tracker, eventData ) { * @inner * @function */ -function onStripScroll( tracker, eventData ) { +function onStripScroll( event ) { var offsetLeft = Number( this.element.style.marginLeft.replace( 'px', '' ) ), offsetTop = Number( this.element.style.marginTop.replace( 'px', '' ) ), scrollWidth = Number( this.element.style.width.replace( 'px', '' ) ), @@ -347,31 +347,31 @@ function onStripScroll( tracker, eventData ) { viewerSize = $.getElementSize( this.viewer.canvas ); if ( this.element ) { if ( 'horizontal' == this.scroll ) { - if ( eventData.scroll > 0 ) { + if ( event.scroll > 0 ) { //forward if ( offsetLeft > -( scrollWidth - viewerSize.x ) ) { - this.element.style.marginLeft = ( offsetLeft - ( eventData.scroll * 60 ) ) + 'px'; - loadPanels( this, viewerSize.x, offsetLeft - ( eventData.scroll * 60 ) ); + this.element.style.marginLeft = ( offsetLeft - ( event.scroll * 60 ) ) + 'px'; + loadPanels( this, viewerSize.x, offsetLeft - ( event.scroll * 60 ) ); } - } else if ( eventData.scroll < 0 ) { + } else if ( event.scroll < 0 ) { //reverse if ( offsetLeft < 0 ) { - this.element.style.marginLeft = ( offsetLeft - ( eventData.scroll * 60 ) ) + 'px'; - loadPanels( this, viewerSize.x, offsetLeft - ( eventData.scroll * 60 ) ); + this.element.style.marginLeft = ( offsetLeft - ( event.scroll * 60 ) ) + 'px'; + loadPanels( this, viewerSize.x, offsetLeft - ( event.scroll * 60 ) ); } } } else { - if ( eventData.scroll < 0 ) { + if ( event.scroll < 0 ) { //scroll up if ( offsetTop > viewerSize.y - scrollHeight ) { - this.element.style.marginTop = ( offsetTop + ( eventData.scroll * 60 ) ) + 'px'; - loadPanels( this, viewerSize.y, offsetTop + ( eventData.scroll * 60 ) ); + this.element.style.marginTop = ( offsetTop + ( event.scroll * 60 ) ) + 'px'; + loadPanels( this, viewerSize.y, offsetTop + ( event.scroll * 60 ) ); } - } else if ( eventData.scroll > 0 ) { + } else if ( event.scroll > 0 ) { //scroll dowm if ( offsetTop < 0 ) { - this.element.style.marginTop = ( offsetTop + ( eventData.scroll * 60 ) ) + 'px'; - loadPanels( this, viewerSize.y, offsetTop + ( eventData.scroll * 60 ) ); + this.element.style.marginTop = ( offsetTop + ( event.scroll * 60 ) ) + 'px'; + loadPanels( this, viewerSize.y, offsetTop + ( event.scroll * 60 ) ); } } } @@ -453,22 +453,22 @@ function loadPanels( strip, viewerSize, scroll ) { * @inner * @function */ -function onStripEnter( tracker, eventData ) { +function onStripEnter( event ) { - //$.setElementOpacity(tracker.element, 0.8); + //$.setElementOpacity(event.eventSource.element, 0.8); - //tracker.element.style.border = '1px solid #555'; - //tracker.element.style.background = '#000'; + //event.eventSource.element.style.border = '1px solid #555'; + //event.eventSource.element.style.background = '#000'; if ( 'horizontal' == this.scroll ) { - //tracker.element.style.paddingTop = "0px"; - tracker.element.style.marginBottom = "0px"; + //event.eventSource.element.style.paddingTop = "0px"; + event.eventSource.element.style.marginBottom = "0px"; } else { - //tracker.element.style.paddingRight = "0px"; - tracker.element.style.marginLeft = "0px"; + //event.eventSource.element.style.paddingRight = "0px"; + event.eventSource.element.style.marginLeft = "0px"; } return false; @@ -480,16 +480,16 @@ function onStripEnter( tracker, eventData ) { * @inner * @function */ -function onStripExit( tracker, eventData ) { +function onStripExit( event ) { if ( 'horizontal' == this.scroll ) { - //tracker.element.style.paddingTop = "10px"; - tracker.element.style.marginBottom = "-" + ( $.getElementSize( tracker.element ).y / 2 ) + "px"; + //event.eventSource.element.style.paddingTop = "10px"; + event.eventSource.element.style.marginBottom = "-" + ( $.getElementSize( event.eventSource.element ).y / 2 ) + "px"; } else { - //tracker.element.style.paddingRight = "10px"; - tracker.element.style.marginLeft = "-" + ( $.getElementSize( tracker.element ).x / 2 ) + "px"; + //event.eventSource.element.style.paddingRight = "10px"; + event.eventSource.element.style.marginLeft = "-" + ( $.getElementSize( event.eventSource.element ).x / 2 ) + "px"; } return false; @@ -502,37 +502,37 @@ function onStripExit( tracker, eventData ) { * @inner * @function */ -function onKeyPress( tracker, eventData ) { - //console.log( eventData.keyCode ); +function onKeyPress( event ) { + //console.log( event.keyCode ); - switch ( eventData.keyCode ) { + switch ( event.keyCode ) { case 61: //=|+ - onStripScroll.call( this, this.tracker, { position: null, scroll: 1, shift: null } ); + onStripScroll.call( this, { eventSource: this.tracker, position: null, scroll: 1, shift: null } ); return false; case 45: //-|_ - onStripScroll.call( this, this.tracker, { position: null, scroll: -1, shift: null } ); + onStripScroll.call( this, { eventSource: this.tracker, position: null, scroll: -1, shift: null } ); return false; case 48: //0|) case 119: //w case 87: //W case 38: //up arrow - onStripScroll.call( this, this.tracker, { position: null, scroll: 1, shift: null } ); + onStripScroll.call( this, { eventSource: this.tracker, position: null, scroll: 1, shift: null } ); return false; case 115: //s case 83: //S case 40: //down arrow - onStripScroll.call( this, this.tracker, { position: null, scroll: -1, shift: null } ); + onStripScroll.call( this, { eventSource: this.tracker, position: null, scroll: -1, shift: null } ); return false; case 97: //a case 37: //left arrow - onStripScroll.call( this, this.tracker, { position: null, scroll: -1, shift: null } ); + onStripScroll.call( this, { eventSource: this.tracker, position: null, scroll: -1, shift: null } ); return false; case 100: //d case 39: //right arrow - onStripScroll.call( this, this.tracker, { position: null, scroll: 1, shift: null } ); + onStripScroll.call( this, { eventSource: this.tracker, position: null, scroll: 1, shift: null } ); return false; default: - //console.log( 'navigator keycode %s', eventData.keyCode ); + //console.log( 'navigator keycode %s', event.keyCode ); return true; } } diff --git a/src/tilesource.js b/src/tilesource.js index 641f0e65..0120e515 100644 --- a/src/tilesource.js +++ b/src/tilesource.js @@ -117,8 +117,8 @@ $.TileSource = function( width, height, tileSize, tileOverlap, minLevel, maxLeve for ( i = 0; i < arguments.length; i++ ) { if ( $.isFunction( arguments[ i ] ) ) { callback = arguments[ i ]; - this.addHandler( 'ready', function ( placeHolderSource, placeHolderEventData ) { - callback( placeHolderSource, placeHolderEventData ); + this.addHandler( 'ready', function ( event ) { + callback( event ); } ); //only one callback per constructor break; diff --git a/src/viewer.js b/src/viewer.js index ecd8560f..1011c58a 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -172,8 +172,8 @@ $.Viewer = function( options ) { //Inherit some behaviors and properties $.EventSource.call( this ); - this.addHandler( 'open-failed', function (source, args) { - var msg = $.getString( "Errors.OpenFailed", args.source, args.message); + this.addHandler( 'open-failed', function ( event ) { + var msg = $.getString( "Errors.OpenFailed", event.eventSource, event.message); _this._showMessage( msg ); }); @@ -265,8 +265,8 @@ $.Viewer = function( options ) { window.scrollTo( 0, point.y ); }, - keyHandler: function( tracker, eventData ){ - switch( eventData.keyCode ){ + keyHandler: function( event ){ + switch( event.keyCode ){ case 61://=|+ _this.viewport.zoomBy(1.1); _this.viewport.applyConstraints(); @@ -282,7 +282,7 @@ $.Viewer = function( options ) { case 119://w case 87://W case 38://up arrow - if ( eventData.shift ) { + if ( event.shift ) { _this.viewport.zoomBy(1.1); } else { _this.viewport.panBy(new $.Point(0, -0.05)); @@ -292,7 +292,7 @@ $.Viewer = function( options ) { case 115://s case 83://S case 40://down arrow - if ( eventData.shift ) { + if ( event.shift ) { _this.viewport.zoomBy(0.9); } else { _this.viewport.panBy(new $.Point(0, 0.05)); @@ -310,7 +310,7 @@ $.Viewer = function( options ) { _this.viewport.applyConstraints(); return false; default: - //console.log( 'navigator keycode %s', eventData.keyCode ); + //console.log( 'navigator keycode %s', event.keyCode ); return true; } } @@ -438,11 +438,11 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, setTimeout(function(){ if ( $.type( tileSource ) == 'string') { //If its still a string it means it must be a url at this point - tileSource = new $.TileSource( tileSource, function( eventSource, eventData ){ - openTileSource( _this, eventData.tileSource ); + tileSource = new $.TileSource( tileSource, function( event ){ + openTileSource( _this, event.tileSource ); }); - tileSource.addHandler( 'open-failed', function ( name, args ) { - _this.raiseEvent( 'open-failed', args ); + tileSource.addHandler( 'open-failed', function ( event ) { + _this.raiseEvent( 'open-failed', event ); }); } else if ( $.isPlainObject( tileSource ) || tileSource.nodeType ){ @@ -506,7 +506,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, VIEWERS[ this.hash ] = null; delete VIEWERS[ this.hash ]; - this.raiseEvent( 'close', { viewer: this } ); + this.raiseEvent( 'close', {} ); return this; }, @@ -569,7 +569,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, */ setMouseNavEnabled: function( enabled ){ this.innerTracker.setTracking( enabled ); - this.raiseEvent( 'mouse-enabled', { enabled: enabled, viewer: this } ); + this.raiseEvent( 'mouse-enabled', { enabled: enabled } ); return this; }, @@ -603,7 +603,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, } else { beginControlsAutoHide( this ); } - this.raiseEvent( 'controls-enabled', { enabled: enabled, viewer: this } ); + this.raiseEvent( 'controls-enabled', { enabled: enabled } ); return this; }, @@ -731,7 +731,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, THIS[ this.hash ].fullPage = true; // mouse will be inside container now - $.delegate( this, onContainerEnter )( null, {} ); + $.delegate( this, onContainerEnter )( {} ); } else { @@ -790,11 +790,11 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, THIS[ this.hash ].fullPage = false; // mouse will likely be outside now - $.delegate( this, onContainerExit )( null, {} ); + $.delegate( this, onContainerExit )( {} ); } - this.raiseEvent( 'fullpage', { fullpage: fullPage, viewer: this } ); + this.raiseEvent( 'fullpage', { fullpage: fullPage } ); if ( this.viewport ) { oldBounds = this.viewport.getBounds(); @@ -854,7 +854,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, */ setVisible: function( visible ){ this.container.style.visibility = visible ? "" : "hidden"; - this.raiseEvent( 'visible', { visible: visible, viewer: this } ); + this.raiseEvent( 'visible', { visible: visible } ); return this; }, @@ -1076,7 +1076,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, goToPage: function( page ){ //page is a 1 based index so normalize now //page = page; - this.raiseEvent( 'page', { page: page, viewer: this } ); + this.raiseEvent( 'page', { page: page } ); if( this.tileSources.length > page ){ @@ -1334,7 +1334,7 @@ function openTileSource( viewer, source ) { } VIEWERS[ _this.hash ] = _this; - _this.raiseEvent( 'open', { source: source, viewer: _this } ); + _this.raiseEvent( 'open', { source: source } ); return _this; } @@ -1427,37 +1427,37 @@ function onBlur(){ } -function onCanvasClick( tracker, eventData ) { +function onCanvasClick( event ) { var zoomPerClick, factor; - if ( this.viewport && eventData.quick ) { // ignore clicks where mouse moved + if ( this.viewport && event.quick ) { // ignore clicks where mouse moved zoomPerClick = this.zoomPerClick; - factor = eventData.shift ? 1.0 / zoomPerClick : zoomPerClick; + factor = event.shift ? 1.0 / zoomPerClick : zoomPerClick; this.viewport.zoomBy( factor, - this.viewport.pointFromPixel( eventData.position, true ) + this.viewport.pointFromPixel( event.position, true ) ); this.viewport.applyConstraints(); } this.raiseEvent( 'canvas-click', { - tracker: tracker, - position: eventData.position, - quick: eventData.quick, - shift: eventData.shift + tracker: event.eventSource, + position: event.position, + quick: event.quick, + shift: event.shift }); } -function onCanvasDrag( tracker, eventData ) { +function onCanvasDrag( event ) { if ( this.viewport ) { if( !this.panHorizontal ){ - eventData.delta.x = 0; + event.delta.x = 0; } if( !this.panVertical ){ - eventData.delta.y = 0; + event.delta.y = 0; } this.viewport.panBy( this.viewport.deltaPointsFromPixels( - eventData.delta.negate() + event.delta.negate() ) ); if( this.constrainDuringPan ){ @@ -1465,83 +1465,83 @@ function onCanvasDrag( tracker, eventData ) { } } this.raiseEvent( 'canvas-drag', { - tracker: tracker, - position: eventData.position, - delta: eventData.delta, - shift: eventData.shift + tracker: event.eventSource, + position: event.position, + delta: event.delta, + shift: event.shift }); } -function onCanvasRelease( tracker, eventData ) { - if ( eventData.insideElementPressed && this.viewport ) { +function onCanvasRelease( event ) { + if ( event.insideElementPressed && this.viewport ) { this.viewport.applyConstraints(); } this.raiseEvent( 'canvas-release', { - tracker: tracker, - position: eventData.position, - insideElementPressed: eventData.insideElementPressed, - insideElementReleased: eventData.insideElementReleased + tracker: event.eventSource, + position: event.position, + insideElementPressed: event.insideElementPressed, + insideElementReleased: event.insideElementReleased }); } -function onCanvasScroll( tracker, eventData ) { +function onCanvasScroll( event ) { var factor; if ( this.viewport ) { - factor = Math.pow( this.zoomPerScroll, eventData.scroll ); + factor = Math.pow( this.zoomPerScroll, event.scroll ); this.viewport.zoomBy( factor, - this.viewport.pointFromPixel( eventData.position, true ) + this.viewport.pointFromPixel( event.position, true ) ); this.viewport.applyConstraints(); } this.raiseEvent( 'canvas-scroll', { - tracker: tracker, - position: eventData.position, - scroll: eventData.scroll, - shift: eventData.shift + tracker: event.eventSource, + position: event.position, + scroll: event.scroll, + shift: event.shift }); //cancels event return false; } -function onContainerExit( tracker, eventData ) { - if ( !eventData.insideElementPressed ) { +function onContainerExit( event ) { + if ( !event.insideElementPressed ) { THIS[ this.hash ].mouseInside = false; if ( !THIS[ this.hash ].animating ) { beginControlsAutoHide( this ); } } this.raiseEvent( 'container-exit', { - tracker: tracker, - position: eventData.position, - insideElementPressed: eventData.insideElementPressed, - buttonDownAny: eventData.buttonDownAny + tracker: event.eventSource, + position: event.position, + insideElementPressed: event.insideElementPressed, + buttonDownAny: event.buttonDownAny }); } -function onContainerRelease( tracker, eventData ) { - if ( !eventData.insideElementReleased ) { +function onContainerRelease( event ) { + if ( !event.insideElementReleased ) { THIS[ this.hash ].mouseInside = false; if ( !THIS[ this.hash ].animating ) { beginControlsAutoHide( this ); } } this.raiseEvent( 'container-release', { - tracker: tracker, - position: eventData.position, - insideElementPressed: eventData.insideElementPressed, - insideElementReleased: eventData.insideElementReleased + tracker: event.eventSource, + position: event.position, + insideElementPressed: event.insideElementPressed, + insideElementReleased: event.insideElementReleased }); } -function onContainerEnter( tracker, eventData ) { +function onContainerEnter( event ) { THIS[ this.hash ].mouseInside = true; abortControlsAutoHide( this ); this.raiseEvent( 'container-enter', { - tracker: tracker, - position: eventData.position, - insideElementPressed: eventData.insideElementPressed, - buttonDownAny: eventData.buttonDownAny + tracker: event.eventSource, + position: event.position, + insideElementPressed: event.insideElementPressed, + buttonDownAny: event.buttonDownAny }); } diff --git a/src/viewport.js b/src/viewport.js index 6d834564..6fa8931f 100644 --- a/src/viewport.js +++ b/src/viewport.js @@ -122,8 +122,7 @@ $.Viewport.prototype = { if( this.viewer ){ this.viewer.raiseEvent( 'reset-size', { - contentSize: contentSize, - viewer: this.viewer + contentSize: contentSize }); } @@ -169,8 +168,7 @@ $.Viewport.prototype = { goHome: function( immediately ) { if( this.viewer ){ this.viewer.raiseEvent( 'home', { - immediately: immediately, - viewer: this.viewer + immediately: immediately }); } return this.fitBounds( this.getHomeBounds(), immediately ); @@ -370,8 +368,7 @@ $.Viewport.prototype = { if( this.viewer ){ this.viewer.raiseEvent( 'constrain', { - immediately: immediately, - viewer: this.viewer + immediately: immediately }); } @@ -523,8 +520,7 @@ $.Viewport.prototype = { if( this.viewer ){ this.viewer.raiseEvent( 'pan', { center: center, - immediately: immediately, - viewer: this.viewer + immediately: immediately }); } @@ -567,8 +563,7 @@ $.Viewport.prototype = { this.viewer.raiseEvent( 'zoom', { zoom: zoom, refPoint: refPoint, - immediately: immediately, - viewer: this.viewer + immediately: immediately }); } @@ -631,8 +626,7 @@ $.Viewport.prototype = { if( this.viewer ){ this.viewer.raiseEvent( 'resize', { newContainerSize: newContainerSize, - maintain: maintain, - viewer: this.viewer + maintain: maintain }); } diff --git a/test/basic.js b/test/basic.js index eb75b947..3ab694f1 100644 --- a/test/basic.js +++ b/test/basic.js @@ -28,11 +28,11 @@ asyncTest('Open', function() { ok(viewer, 'Viewer exists'); - var openHandler = function(eventSender, eventData) { + var openHandler = function(event) { viewer.removeHandler('open', openHandler); ok(true, 'Open event was sent'); - equal(eventSender, viewer, 'Sender of open event was viewer'); - ok(eventData, 'Handler also received event data'); + ok(event, 'Handler received event data'); + equal(event.eventSource, viewer, 'Sender of open event was viewer'); ok(viewer.viewport, 'Viewport exists'); ok(viewer.source, 'source exists'); ok(viewer._updateRequestId, 'timer is on'); @@ -46,12 +46,12 @@ asyncTest('Open Error Handling', function() { ok(viewer, 'Viewer exists'); - viewer.addHandler('open', function(eventSender, eventData) { + viewer.addHandler('open', function(event) { ok(false, "The open event should not fire for failed opens"); start(); }); - viewer.addHandler('open-failed', function(eventSender, eventData) { + viewer.addHandler('open-failed', function(event) { ok(true, "The open-failed event should be fired when the source 404s"); equal($(".openseadragon-message").length, 1, "Open failures should display a message"); diff --git a/test/events.js b/test/events.js index d99799be..9c8fefbb 100644 --- a/test/events.js +++ b/test/events.js @@ -26,11 +26,12 @@ // ---------- asyncTest( 'addHandler without userData', function () { - var openHandler = function ( eventSender, eventData ) { + var openHandler = function ( event ) { viewer.removeHandler( 'open', openHandler ); - ok( eventData, 'Event handler received event data' ); - if ( eventData ) { - strictEqual( eventData.userData, null, 'User data defaulted to null' ); + ok( event, 'Event handler received event data' ); + if ( event ) { + strictEqual( event.eventSource, viewer, 'eventSource sent, eventSource is viewer' ); + strictEqual( event.userData, null, 'User data defaulted to null' ); } viewer.close(); start(); @@ -45,12 +46,12 @@ var userData = { item1: 'Test user data', item2: Math.random() }, originalUserData = { item1: userData.item1, item2: userData.item2 }; - var openHandler = function ( eventSender, eventData ) { + var openHandler = function ( event ) { viewer.removeHandler( 'open', openHandler ); - ok( eventData, 'Event handler received event data' ); - ok( eventData && eventData.userData, 'Event handler received user data' ); - if ( eventData && eventData.userData ) { - deepEqual( eventData.userData, originalUserData, 'User data was untouched' ); + ok( event, 'Event handler received event data' ); + ok( event && event.userData, 'Event handler received user data' ); + if ( event && event.userData ) { + deepEqual( event.userData, originalUserData, 'User data was untouched' ); } viewer.close(); start(); @@ -71,11 +72,12 @@ releasesHandledEventSource = 0, clicksHandledEventSource = 0, eventsHandledMouseTracker = 0, + eventSourcePassedMouseTracker = 0, originalEventsPassedMouseTracker = 0, releasesExpected = 1, clicksExpected = 1; - var onOpen = function ( eventSender, eventData ) { + var onOpen = function ( event ) { viewer.removeHandler( 'open', onOpen ); viewer.addHandler( 'canvas-drag', onEventSourceDrag ); @@ -115,61 +117,64 @@ $canvas.simulate( 'blur', event ); }; - var onEventSourceDrag = function ( eventSender, eventData ) { + var onEventSourceDrag = function ( event ) { dragsHandledEventSource++; }; - var onEventSourceRelease = function ( eventSender, eventData ) { + var onEventSourceRelease = function ( event ) { releasesHandledEventSource++; }; - var onEventSourceClick = function ( eventSender, eventData ) { + var onEventSourceClick = function ( event ) { clicksHandledEventSource++; }; - var checkOriginalEventReceived = function ( eventData ) { + var checkOriginalEventReceived = function ( event ) { eventsHandledMouseTracker++; + if ( event && event.eventSource === mouseTracker ) { + eventSourcePassedMouseTracker++; + } //TODO Provide a better check for the original event...simulate doesn't currently extend the object // with arbitrary user data. - if ( eventData && eventData.originalEvent ) { + if ( event && event.originalEvent ) { originalEventsPassedMouseTracker++; } }; - var onMouseTrackerFocus = function ( tracker, eventData ) { - checkOriginalEventReceived( eventData ); + var onMouseTrackerFocus = function ( event ) { + checkOriginalEventReceived( event ); }; - var onMouseTrackerBlur = function ( tracker, eventData ) { - checkOriginalEventReceived( eventData ); + var onMouseTrackerBlur = function ( event ) { + checkOriginalEventReceived( event ); }; - var onMouseTrackerEnter = function ( tracker, eventData ) { - checkOriginalEventReceived( eventData ); + var onMouseTrackerEnter = function ( event ) { + checkOriginalEventReceived( event ); }; - var onMouseTrackerPress = function ( tracker, eventData ) { - checkOriginalEventReceived( eventData ); + var onMouseTrackerPress = function ( event ) { + checkOriginalEventReceived( event ); }; - var onMouseTrackerMove = function ( tracker, eventData ) { - checkOriginalEventReceived( eventData ); + var onMouseTrackerMove = function ( event ) { + checkOriginalEventReceived( event ); }; - var onMouseTrackerDrag = function ( tracker, eventData ) { - checkOriginalEventReceived( eventData ); + var onMouseTrackerDrag = function ( event ) { + checkOriginalEventReceived( event ); }; - var onMouseTrackerRelease = function ( tracker, eventData ) { - checkOriginalEventReceived( eventData ); + var onMouseTrackerRelease = function ( event ) { + checkOriginalEventReceived( event ); }; - var onMouseTrackerClick = function ( tracker, eventData ) { - checkOriginalEventReceived( eventData ); + var onMouseTrackerClick = function ( event ) { + checkOriginalEventReceived( event ); }; - var onMouseTrackerExit = function ( tracker, eventData ) { - checkOriginalEventReceived( eventData ); + var onMouseTrackerExit = function ( event ) { + checkOriginalEventReceived( event ); mouseTracker.destroy(); viewer.removeHandler( 'canvas-drag', onEventSourceDrag ); @@ -180,8 +185,9 @@ equal( releasesHandledEventSource, releasesExpected, "'canvas-release' event count matches expected (" + releasesExpected + ")" ); equal( clicksHandledEventSource, releasesExpected, "'canvas-click' event count matches expected (" + releasesExpected + ")" ); + equal( eventSourcePassedMouseTracker, eventsHandledMouseTracker, "Event source received count matches expected (" + eventsHandledMouseTracker + ")" ); equal( originalEventsPassedMouseTracker, eventsHandledMouseTracker, "Original event received count matches expected (" + eventsHandledMouseTracker + ")" ); - deepEqual( eventData.userData, originalUserData, 'MouseTracker userData was untouched' ); + deepEqual( event.userData, originalUserData, 'MouseTracker userData was untouched' ); viewer.close(); start(); diff --git a/test/formats.js b/test/formats.js index 7a81c4f7..e0915a5c 100644 --- a/test/formats.js +++ b/test/formats.js @@ -26,20 +26,20 @@ ok(viewer, 'Viewer exists'); - var openHandler = function(eventSender, eventData) { + var openHandler = function(event) { viewer.removeHandler('open', openHandler); ok(true, 'Open event was sent'); viewer.addHandler('tile-drawn', tileDrawnHandler); }; - var tileDrawnHandler = function(eventSender, eventData) { + var tileDrawnHandler = function(event) { viewer.removeHandler('tile-drawn', tileDrawnHandler); ok(true, 'A tile has been drawn'); viewer.addHandler('close', closeHandler); viewer.close(); }; - var closeHandler = function() { + var closeHandler = function(event) { viewer.removeHandler('close', closeHandler); $('#example').empty(); ok(true, 'Close event was sent'); diff --git a/test/navigator.js b/test/navigator.js index 62899328..f63c8cd0 100644 --- a/test/navigator.js +++ b/test/navigator.js @@ -479,13 +479,13 @@ QUnit.config.autostart = false; showNavigator: true }); - var openHandler1 = function(eventSender, eventData) { + var openHandler1 = function(event) { viewer.removeHandler('open', openHandler1); ok(viewer.navigator, 'navigator exists'); viewer.navigator.addHandler('open', navOpenHandler1); }; - var navOpenHandler1 = function(eventSender, eventData) { + var navOpenHandler1 = function(event) { viewer.navigator.removeHandler('open', navOpenHandler1); equal(viewer.navigator.source, viewer.source, 'viewer and navigator have the same source'); ok(viewer.navigator._updateRequestId, 'navigator timer is on'); @@ -494,25 +494,25 @@ QUnit.config.autostart = false; viewer.open('/test/data/tall.dzi'); }; - var closeHandler1 = function() { + var closeHandler1 = function(event) { viewer.removeHandler('close', closeHandler1); ok(true, 'calling open closes the old one'); equal(viewer.navigator.source, null, 'navigator source has been cleared'); }; - var openHandler2 = function(eventSender, eventData) { + var openHandler2 = function(event) { viewer.removeHandler('open', openHandler2); viewer.navigator.addHandler('open', navOpenHandler2); }; - var navOpenHandler2 = function(eventSender, eventData) { + var navOpenHandler2 = function(event) { viewer.navigator.removeHandler('open', navOpenHandler2); equal(viewer.navigator.source, viewer.source, 'viewer and navigator have the same source'); viewer.addHandler('close', closeHandler2); viewer.close(); }; - var closeHandler2 = function() { + var closeHandler2 = function(event) { viewer.removeHandler('close', closeHandler2); ok(!viewer.navigator._updateRequestId, 'navigator timer is off'); setTimeout(function() {