Merge pull request #257 from msalsbery/EventSource-Original-Events

originalEvent Pass through to EventSource events (#227)
This commit is contained in:
iangilman 2013-10-22 10:31:18 -07:00
commit 5d45054fee
4 changed files with 42 additions and 17 deletions

View File

@ -30,6 +30,9 @@ OPENSEADRAGON CHANGELOG
* Added a number of easier coordinate conversion methods to viewport (#243)
* Added the ability to create a viewer and start at a specified page (#252)
* Fixed image resolve issue with collection mode (#255)
* DOM events are now passed through as 'event.originalEvent' in viewer and button events where appropriate. Affects the following events:
* Viewer: 'canvas-release', 'canvas-click', 'canvas-drag', 'canvas-scroll', 'container-enter', 'container-exit', 'container-release'
* Button: 'enter', 'exit', 'press', 'release', 'focus', 'blur', 'click'
0.9.131:

View File

@ -178,7 +178,7 @@ $.Button = function( options ) {
enterHandler: function( event ) {
if ( event.insideElementPressed ) {
inTo( _this, $.ButtonState.DOWN );
_this.raiseEvent( "enter", {} );
_this.raiseEvent( "enter", { originalEvent: event.originalEvent } );
} else if ( !event.buttonDownAny ) {
inTo( _this, $.ButtonState.HOVER );
}
@ -186,30 +186,30 @@ $.Button = function( options ) {
focusHandler: function ( event ) {
this.enterHandler( event );
_this.raiseEvent( "focus", {} );
_this.raiseEvent( "focus", { originalEvent: event.originalEvent } );
},
exitHandler: function( event ) {
outTo( _this, $.ButtonState.GROUP );
if ( event.insideElementPressed ) {
_this.raiseEvent( "exit", {} );
_this.raiseEvent( "exit", { originalEvent: event.originalEvent } );
}
},
blurHandler: function ( event ) {
this.exitHandler( event );
_this.raiseEvent( "blur", {} );
_this.raiseEvent( "blur", { originalEvent: event.originalEvent } );
},
pressHandler: function ( event ) {
inTo( _this, $.ButtonState.DOWN );
_this.raiseEvent( "press", {} );
_this.raiseEvent( "press", { originalEvent: event.originalEvent } );
},
releaseHandler: function( event ) {
if ( event.insideElementPressed && event.insideElementReleased ) {
outTo( _this, $.ButtonState.HOVER );
_this.raiseEvent( "release", {} );
_this.raiseEvent( "release", { originalEvent: event.originalEvent } );
} else if ( event.insideElementPressed ) {
outTo( _this, $.ButtonState.GROUP );
} else {
@ -219,15 +219,15 @@ $.Button = function( options ) {
clickHandler: function( event ) {
if ( event.quick ) {
_this.raiseEvent("click", {});
_this.raiseEvent("click", { originalEvent: event.originalEvent });
}
},
keyHandler: function( event ){
//console.log( "%s : handling key %s!", _this.tooltip, event.keyCode);
if( 13 === event.keyCode ){
_this.raiseEvent( "click", {} );
_this.raiseEvent( "release", {} );
_this.raiseEvent( "click", { originalEvent: event.originalEvent } );
_this.raiseEvent( "release", { originalEvent: event.originalEvent } );
return false;
}
return true;

View File

@ -530,7 +530,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
VIEWERS[ this.hash ] = null;
delete VIEWERS[ this.hash ];
this.raiseEvent( 'close', {} );
this.raiseEvent( 'close' );
return this;
},
@ -1487,7 +1487,8 @@ function onCanvasClick( event ) {
tracker: event.eventSource,
position: event.position,
quick: event.quick,
shift: event.shift
shift: event.shift,
originalEvent: event.originalEvent
});
}
@ -1512,7 +1513,8 @@ function onCanvasDrag( event ) {
tracker: event.eventSource,
position: event.position,
delta: event.delta,
shift: event.shift
shift: event.shift,
originalEvent: event.originalEvent
});
}
@ -1524,7 +1526,8 @@ function onCanvasRelease( event ) {
tracker: event.eventSource,
position: event.position,
insideElementPressed: event.insideElementPressed,
insideElementReleased: event.insideElementReleased
insideElementReleased: event.insideElementReleased,
originalEvent: event.originalEvent
});
}
@ -1542,7 +1545,8 @@ function onCanvasScroll( event ) {
tracker: event.eventSource,
position: event.position,
scroll: event.scroll,
shift: event.shift
shift: event.shift,
originalEvent: event.originalEvent
});
//cancels event
return false;
@ -1559,7 +1563,8 @@ function onContainerExit( event ) {
tracker: event.eventSource,
position: event.position,
insideElementPressed: event.insideElementPressed,
buttonDownAny: event.buttonDownAny
buttonDownAny: event.buttonDownAny,
originalEvent: event.originalEvent
});
}
@ -1574,7 +1579,8 @@ function onContainerRelease( event ) {
tracker: event.eventSource,
position: event.position,
insideElementPressed: event.insideElementPressed,
insideElementReleased: event.insideElementReleased
insideElementReleased: event.insideElementReleased,
originalEvent: event.originalEvent
});
}
@ -1585,7 +1591,8 @@ function onContainerEnter( event ) {
tracker: event.eventSource,
position: event.position,
insideElementPressed: event.insideElementPressed,
buttonDownAny: event.buttonDownAny
buttonDownAny: event.buttonDownAny,
originalEvent: event.originalEvent
});
}

View File

@ -74,6 +74,8 @@
eventsHandledMouseTracker = 0,
eventSourcePassedMouseTracker = 0,
originalEventsPassedMouseTracker = 0,
eventsHandledViewer = 0,
originalEventsPassedViewer = 0,
releasesExpected = 1,
clicksExpected = 1;
@ -117,15 +119,27 @@
$canvas.simulate( 'blur', event );
};
var checkOriginalEventReceivedViewer = function ( event ) {
eventsHandledViewer++;
//TODO Provide a better check for the original event...simulate doesn't currently extend the object
// with arbitrary user data.
if ( event && event.originalEvent ) {
originalEventsPassedViewer++;
}
};
var onEventSourceDrag = function ( event ) {
checkOriginalEventReceivedViewer( event );
dragsHandledEventSource++;
};
var onEventSourceRelease = function ( event ) {
checkOriginalEventReceivedViewer( event );
releasesHandledEventSource++;
};
var onEventSourceClick = function ( event ) {
checkOriginalEventReceivedViewer( event );
clicksHandledEventSource++;
};
@ -184,6 +198,7 @@
equal( dragsHandledEventSource, dragCount, "'canvas-drag' event count matches 'mousemove' event count (" + dragCount + ")" );
equal( releasesHandledEventSource, releasesExpected, "'canvas-release' event count matches expected (" + releasesExpected + ")" );
equal( clicksHandledEventSource, releasesExpected, "'canvas-click' event count matches expected (" + releasesExpected + ")" );
equal( originalEventsPassedViewer, eventsHandledViewer, "Original event received count matches expected (" + eventsHandledViewer + ")" );
equal( eventSourcePassedMouseTracker, eventsHandledMouseTracker, "Event source received count matches expected (" + eventsHandledMouseTracker + ")" );
equal( originalEventsPassedMouseTracker, eventsHandledMouseTracker, "Original event received count matches expected (" + eventsHandledMouseTracker + ")" );