cleaning up event names, reducing demo cases to just addHandler interface, normalizing event data to express more idiomatic javascript pattern of passing object instead of invoking callback with positional parameters

This commit is contained in:
thatcher 2013-03-06 17:34:12 -05:00
parent a432a38d3d
commit 6285a779f3
3 changed files with 218 additions and 276 deletions

View File

@ -141,41 +141,81 @@ $.Button = function( options ) {
clickTimeThreshold: this.clickTimeThreshold,
clickDistThreshold: this.clickDistThreshold,
enterHandler: function( tracker, position, buttonDownElement, buttonDownAny ) {
enterHandler: function( tracker, position, buttonDownElement, buttonDownAny, event ) {
if ( buttonDownElement ) {
inTo( _this, $.ButtonState.DOWN );
_this.raiseEvent( "onEnter", _this );
_this.raiseEvent( "enter", {
button: _this,
tracker: tracker,
position: position,
buttonDownElement: buttonDownElement,
buttonDownAny: buttonDownAny,
originalEvent: event
});
} else if ( !buttonDownAny ) {
inTo( _this, $.ButtonState.HOVER );
}
},
focusHandler: function( tracker, position, buttonDownElement, buttonDownAny ) {
this.enterHandler( tracker, position, buttonDownElement, buttonDownAny );
_this.raiseEvent( "onFocus", _this );
focusHandler: function( tracker, position, buttonDownElement, buttonDownAny, event ) {
this.enterHandler( tracker, position, buttonDownElement, buttonDownAny, event );
_this.raiseEvent( "focus", {
button: _this,
tracker: tracker,
position: position,
buttonDownElement: buttonDownElement,
buttonDownAny: buttonDownAny,
originalEvent: event
});
},
exitHandler: function( tracker, position, buttonDownElement, buttonDownAny ) {
exitHandler: function( tracker, position, buttonDownElement, buttonDownAny, event ) {
outTo( _this, $.ButtonState.GROUP );
if ( buttonDownElement ) {
_this.raiseEvent( "onExit", _this );
_this.raiseEvent( "exit", {
button: _this,
tracker: tracker,
position: position,
buttonDownElement: buttonDownElement,
buttonDownAny: buttonDownAny,
originalEvent: event
});
}
},
blurHandler: function( tracker, position, buttonDownElement, buttonDownAny ) {
this.exitHandler( tracker, position, buttonDownElement, buttonDownAny );
_this.raiseEvent( "onBlur", _this );
blurHandler: function( tracker, position, buttonDownElement, buttonDownAny, event ) {
this.exitHandler( tracker, position, buttonDownElement, buttonDownAny, event );
_this.raiseEvent( "blur", {
button: _this,
tracker: tracker,
position: position,
buttonDownElement: buttonDownElement,
buttonDownAny: buttonDownAny,
originalEvent: event
});
},
pressHandler: function( tracker, position ) {
pressHandler: function( tracker, position, event ) {
inTo( _this, $.ButtonState.DOWN );
_this.raiseEvent( "onPress", _this );
_this.raiseEvent( "press", {
button: _this,
tracker: tracker,
position: position,
originalEvent: event
});
},
releaseHandler: function( tracker, position, insideElementPress, insideElementRelease ) {
releaseHandler: function( tracker, position, insideElementPress, insideElementRelease, event ) {
if ( insideElementPress && insideElementRelease ) {
outTo( _this, $.ButtonState.HOVER );
_this.raiseEvent( "onRelease", _this );
_this.raiseEvent( "release", {
button: _this,
tracker: tracker,
position: position,
insideElementPress: insideElementPress,
insideElementRelease: insideElementRelease,
originalEvent: event
});
} else if ( insideElementPress ) {
outTo( _this, $.ButtonState.GROUP );
} else {
@ -183,17 +223,28 @@ $.Button = function( options ) {
}
},
clickHandler: function( tracker, position, quick, shift ) {
clickHandler: function( tracker, position, quick, shift, event ) {
if ( quick ) {
_this.raiseEvent("onClick", _this);
_this.raiseEvent("click", {
button: _this,
tracker: tracker,
position: position,
quick: quick,
shift: shift,
originalEvent: event
});
}
},
keyHandler: function( tracker, key ){
keyHandler: function( tracker, key, event ){
//console.log( "%s : handling key %s!", _this.tooltip, key);
if( 13 === key ){
_this.raiseEvent( "onClick", _this );
_this.raiseEvent( "onRelease", _this );
_this.raiseEvent( "keypress", {
button: _this,
tracker: tracker,
key: key,
originalEvent: event
});
return false;
}
return true;

View File

@ -1169,7 +1169,7 @@ function onBlur(){
}
function onCanvasClick( tracker, position, quick, shift ) {
function onCanvasClick( tracker, position, quick, shift, event ) {
var zoomPreClick,
factor;
if ( this.viewport && quick ) { // ignore clicks where mouse moved
@ -1181,15 +1181,16 @@ function onCanvasClick( tracker, position, quick, shift ) {
);
this.viewport.applyConstraints();
}
this.raiseEvent( 'canvas-click', {
this.raiseEvent( 'click', {
tracker: tracker,
position: position,
quick: quick,
shift: shift
shift: shift,
originalEvent: event
});
}
function onCanvasDrag( tracker, position, delta, shift ) {
function onCanvasDrag( tracker, position, delta, shift, event ) {
if ( this.viewport ) {
if( !this.panHorizontal ){
delta.x = 0;
@ -1206,27 +1207,29 @@ function onCanvasDrag( tracker, position, delta, shift ) {
this.viewport.applyConstraints();
}
}
this.raiseEvent( 'canvas-click', {
this.raiseEvent( 'drag', {
tracker: tracker,
position: position,
delta: delta,
shift: shift
shift: shift,
originalEvent: event
});
}
function onCanvasRelease( tracker, position, insideElementPress, insideElementRelease ) {
function onCanvasRelease( tracker, position, insideElementPress, insideElementRelease, event ) {
if ( insideElementPress && this.viewport ) {
this.viewport.applyConstraints();
}
this.raiseEvent( 'canvas-release', {
this.raiseEvent( 'release', {
tracker: tracker,
position: position,
insideElementPress: insideElementPress,
insideElementRelease: insideElementRelease
insideElementRelease: insideElementRelease,
originalEvent: event
});
}
function onCanvasScroll( tracker, position, scroll, shift ) {
function onCanvasScroll( tracker, position, scroll, shift, event ) {
var factor;
if ( this.viewport ) {
factor = Math.pow( this.zoomPerScroll, scroll );
@ -1236,54 +1239,58 @@ function onCanvasScroll( tracker, position, scroll, shift ) {
);
this.viewport.applyConstraints();
}
this.raiseEvent( 'canvas-scroll', {
this.raiseEvent( 'scroll', {
tracker: tracker,
position: position,
scroll: scroll,
shift: shift
shift: shift,
originalEvent: event
});
//cancels event
return false;
}
function onContainerExit( tracker, position, buttonDownElement, buttonDownAny ) {
function onContainerExit( tracker, position, buttonDownElement, buttonDownAny, event ) {
if ( !buttonDownElement ) {
THIS[ this.hash ].mouseInside = false;
if ( !THIS[ this.hash ].animating ) {
beginControlsAutoHide( this );
}
}
this.raiseEvent( 'container-exit', {
this.raiseEvent( 'exit', {
tracker: tracker,
position: position,
buttonDownElement: buttonDownElement,
buttonDownAny: buttonDownAny
buttonDownAny: buttonDownAny,
originalEvent: event
});
}
function onContainerRelease( tracker, position, insideElementPress, insideElementRelease ) {
function onContainerRelease( tracker, position, insideElementPress, insideElementRelease, event ) {
if ( !insideElementRelease ) {
THIS[ this.hash ].mouseInside = false;
if ( !THIS[ this.hash ].animating ) {
beginControlsAutoHide( this );
}
}
this.raiseEvent( 'container-release', {
this.raiseEvent( 'release', {
tracker: tracker,
position: position,
insideElementPress: insideElementPress,
insideElementRelease: insideElementRelease
insideElementRelease: insideElementRelease,
originalEvent: event
});
}
function onContainerEnter( tracker, position, buttonDownElement, buttonDownAny ) {
function onContainerEnter( tracker, position, buttonDownElement, buttonDownAny, event ) {
THIS[ this.hash ].mouseInside = true;
abortControlsAutoHide( this );
this.raiseEvent( 'container-enter', {
this.raiseEvent( 'enter', {
tracker: tracker,
position: position,
buttonDownElement: buttonDownElement,
buttonDownAny: buttonDownAny
buttonDownAny: buttonDownAny,
originalEvent: event
});
}

View File

@ -5,290 +5,174 @@
<style type="text/css">
.openseadragon
{
width: 800px;
height: 600px;
border: 1px solid black;
color: #333; /* text color for messages */
background-color: black;
width: 800px;
height: 600px;
border: 1px solid black;
color: #333; /* text color for messages */
background-color: black;
}
.openseadragon-small
{
width: 40px;
height: 30px;
border: 1px solid black;
color: #333; /* text color for messages */
background-color: black;
width: 40px;
height: 30px;
border: 1px solid black;
color: #333; /* text color for messages */
background-color: black;
}
</style>
</head>
<body>
<div class="demoarea">
<div>
Simple demo page to verify that event handlers pass along the original source event
</div>
<div id="contentDiv" class="openseadragon"></div>
<div>
<span id='consolelog'></span>
</div>
<div>
Simple demo page to verify that event handlers pass along the original source event
</div>
<div id="contentDiv" class="openseadragon"></div>
<div>
<span id='consolelog'></span>
</div>
</div>
<script type="text/javascript">
var viewer = OpenSeadragon({
id:"contentDiv",
prefixUrl:"openseadragon/build/openseadragon/images/",
id:"contentDiv",
prefixUrl:"openseadragon/build/openseadragon/images/",
tileSources:{
Image:{
xmlns:"http://schemas.microsoft.com/deepzoom/2008",
Url:"example-images/highsmith/highsmith_files/",
Format:"jpg",
Overlap:"2",
TileSize:"256",
Size:{
Height:"9221",
Width:"7026"
}
xmlns:"http://schemas.microsoft.com/deepzoom/2008",
Url:"example-images/highsmith/highsmith_files/",
Format:"jpg",
Overlap:"2",
TileSize:"256",
Size:{
Height:"9221",
Width:"7026"
}
}
}
}
});
var demoMessageLog = "";
var screenConsole = document.getElementById('consolelog');
function checkIfEventWasPassed(event)
{
if(typeof event === 'undefined')
{
demoMessageLog += "PROBLEM EVENT WAS UNDEFINED:" + event + "\n\n";
function checkIfEventWasPassed(event){
if(typeof event === 'undefined'){
demoMessageLog += "PROBLEM EVENT WAS UNDEFINED:" + event + "\n\n";
}
}
function updateDebugMessageOnScreenConsole()
{
function logMessage(){
screenConsole.innerHTML = demoMessageLog.replace(/\n/g, '<br />');
}
viewer.innerTracker.clickHandler = function(tracker, position, delta, shift,event)
{
demoMessageLog += "Altered version of original clickHandler\n" +
" tracker:" + tracker + "\n" +
" position:" + position + "\n" +
" delta:" + delta + "\n" +
" shift:" + shift + "\n" +
" event:" + event + "\n\n";
checkIfEventWasPassed(event);
updateDebugMessageOnScreenConsole();
}
viewer.addHandler("click", function(tracker, position, delta, shift,event)
{
demoMessageLog += "Additional clickHandler\n" +
" tracker:" + tracker + "\n" +
" position:" + position + "\n" +
" delta:" + delta + "\n" +
" shift:" + shift + "\n" +
" event:" + event + "\n\n";
checkIfEventWasPassed(event);
updateDebugMessageOnScreenConsole();
});
viewer.innerTracker.pressHandler = function(tracker, position, event)
{
demoMessageLog += "Altered version of original pressHandler\n" +
" tracker:" + tracker + "\n" +
" position:" + position + "\n" +
" event:" + event + "\n\n";
checkIfEventWasPassed(event);
updateDebugMessageOnScreenConsole();
};
viewer.addHandler("press", function(tracker, position,event)
{
demoMessageLog += "Additional pressHandler\n" +
" tracker:" + tracker + "\n" +
" position:" + position + "\n" +
" event:" + event + "\n\n";
checkIfEventWasPassed(event);
updateDebugMessageOnScreenConsole();
viewer.addHandler("click", function( event ){
demoMessageLog += "Additional clickHandler\n" +
" tracker:" + event.tracker + "\n" +
" position:" + event.position + "\n" +
" delta:" + event.delta + "\n" +
" shift:" + event.shift + "\n" +
" originalEvent:" + event.originalEvent + "\n\n";
checkIfEventWasPassed( event.originalEvent );
logMessage();
});
viewer.innerTracker.releaseHandler = function(tracker, position,buttonDown,insideElementRelease,event)
{
demoMessageLog += "Altered version of original releaseHandler\n" +
" tracker:" + tracker + "\n" +
" position:" + position + "\n" +
" buttonDown:" + buttonDown + "\n" +
" insideElementRelease:" + insideElementRelease + "\n" +
" event:" + event + "\n\n";
checkIfEventWasPassed(event);
updateDebugMessageOnScreenConsole();
};
viewer.addHandler("release", function(tracker, position ,buttonDown,insideElementRelease,event)
{
demoMessageLog += "Additional releaseHandler\n" +
" tracker:" + tracker + "\n" +
" position:" + position + "\n" +
" buttonDown:" + buttonDown + "\n" +
" insideElementRelease:" + insideElementRelease + "\n" +
" event:" + event + "\n\n";
checkIfEventWasPassed(event);
updateDebugMessageOnScreenConsole();
});
viewer.innerTracker.keyHandler = function(tracker, keycode, shift,event)
{
demoMessageLog += "Altered version of original keyHandler\n" +
" tracker:" + tracker + "\n" +
" keycode:" + keycode + "\n" +
" shift:" + shift + "\n" +
" event:" + event + "\n\n";
checkIfEventWasPassed(event);
updateDebugMessageOnScreenConsole();
};
viewer.addHandler("keypress", function(tracker, keycode, shift,event)
{
demoMessageLog += "Additional keyHandler\n" +
" tracker:" + tracker + "\n" +
" keycode:" + keycode + "\n" +
" shift:" + shift + "\n" +
" event:" + event + "\n\n";
checkIfEventWasPassed(event);
updateDebugMessageOnScreenConsole();
viewer.addHandler("press", function( event ){
demoMessageLog += "Additional pressHandler\n" +
" tracker:" + event.tracker + "\n" +
" position:" + event.position + "\n" +
" originalEvent:" + event.originalEvent + "\n\n";
checkIfEventWasPassed( event.originalEvent );
logMessage();
});
viewer.innerTracker.dragHandler = function(tracker, position, delta, shift,event)
{
demoMessageLog += "Altered version of original dragHandler\n" +
" tracker:" + tracker + "\n" +
" position:" + position + "\n" +
" delta:" + delta + "\n" +
" shift:" + shift + "\n" +
" event:" + event + "\n\n";
checkIfEventWasPassed(event);
updateDebugMessageOnScreenConsole();
};
viewer.addHandler("drag", function(tracker, position, delta, shift,event)
{
demoMessageLog += "Additional dragHandler\n" +
" tracker:" + tracker + "\n" +
" position:" + position + "\n" +
" delta:" + delta + "\n" +
" shift:" + shift + "\n" +
" event:" + event + "\n\n";
checkIfEventWasPassed(event);
updateDebugMessageOnScreenConsole();
viewer.addHandler("release", function( event ){
demoMessageLog += "Additional releaseHandler\n" +
" tracker:" + event.tracker + "\n" +
" position:" + event.position + "\n" +
" buttonDown:" + event.buttonDown + "\n" +
" insideElementRelease:" + event.insideElementRelease + "\n" +
" originalEvent:" + event.originalEvent + "\n\n";
checkIfEventWasPassed( event.originalEvent );
logMessage();
});
viewer.innerTracker.scrollHandler = function(tracker, position, scroll, shift,event)
{
demoMessageLog += "Altered version of original scrollHandler\n" +
" tracker:" + tracker + "\n" +
" position:" + position + "\n" +
" scroll:" + scroll + "\n" +
" shift:" + shift + "\n" +
" event:" + event + "\n\n";
checkIfEventWasPassed(event);
updateDebugMessageOnScreenConsole();
};
viewer.addHandler("scroll", function(tracker, position, scroll, shift,event)
{
demoMessageLog += "Additional scrollHandler\n" +
" tracker:" + tracker + "\n" +
" position:" + position + "\n" +
" scroll:" + scroll + "\n" +
" shift:" + shift + "\n" +
" event:" + event + "\n\n";
checkIfEventWasPassed(event);
updateDebugMessageOnScreenConsole();
viewer.addHandler("keypress", function( event ){
demoMessageLog += "Additional keyHandler\n" +
" tracker:" + event.tracker + "\n" +
" keycode:" + event.keycode + "\n" +
" shift:" + event.shift + "\n" +
" originalEvent:" + event.originalEvent + "\n\n";
checkIfEventWasPassed( event.originalEvent );
logMessage();
});
viewer.innerTracker.enterHandler = function(tracker, position, buttonDown, buttonDownAny,event)
{
demoMessageLog += "Altered version of original enterHandler\n" +
" tracker:" + tracker + "\n" +
" position:" + position + "\n" +
" buttonDown:" + buttonDown + "\n" +
" buttonDownAny:" + buttonDownAny + "\n" +
" event:" + event + "\n\n";
checkIfEventWasPassed(event);
updateDebugMessageOnScreenConsole();
};
viewer.addHandler("enter", function(tracker, position, buttonDown, buttonDownAny,event)
{
demoMessageLog += "Additional enterHandler\n" +
" tracker:" + tracker + "\n" +
" position:" + position + "\n" +
" buttonDown:" + buttonDown + "\n" +
" buttonDownAny:" + buttonDownAny + "\n" +
" event:" + event + "\n\n";
checkIfEventWasPassed(event);
updateDebugMessageOnScreenConsole();
viewer.addHandler("drag", function( event ){
demoMessageLog += "Additional dragHandler\n" +
" tracker:" + event.tracker + "\n" +
" position:" + event.position + "\n" +
" delta:" + event.delta + "\n" +
" shift:" + event.shift + "\n" +
" originalEvent:" + event.originalEvent + "\n\n";
checkIfEventWasPassed( event.originalEvent );
logMessage();
});
viewer.innerTracker.exitHandler = function(tracker, position, buttonDown, buttonDownAny,event)
{
demoMessageLog += "Altered version of original exitHandler\n" +
" tracker:" + tracker + "\n" +
" position:" + position + "\n" +
" buttonDown:" + buttonDown + "\n" +
" buttonDownAny:" + buttonDownAny + "\n" +
" event:" + event + "\n\n";
checkIfEventWasPassed(event);
updateDebugMessageOnScreenConsole();
};
viewer.addHandler("exit", function(tracker, position, buttonDown, buttonDownAny,event)
{
demoMessageLog += "Additional exitHandler\n" +
" tracker:" + tracker + "\n" +
" position:" + position + "\n" +
" buttonDown:" + buttonDown + "\n" +
" buttonDownAny:" + buttonDownAny + "\n" +
" event:" + event + "\n\n";
checkIfEventWasPassed(event);
updateDebugMessageOnScreenConsole();
viewer.addHandler("scroll", function( event ){
demoMessageLog += "Additional scrollHandler\n" +
" tracker:" + event.tracker + "\n" +
" position:" + event.position + "\n" +
" scroll:" + event.scroll + "\n" +
" shift:" + event.shift + "\n" +
" originalEvent:" + event.originalEvent + "\n\n";
checkIfEventWasPassed( event.originalEvent );
logMessage();
});
viewer.innerTracker.focusHandler = function(tracker, event)
{
demoMessageLog += "Altered version of original focusHandler\n" +
" tracker:" + tracker + "\n" +
" event:" + event + "\n\n";
checkIfEventWasPassed(event);
updateDebugMessageOnScreenConsole();
};
viewer.addHandler("focus", function(tracker, event)
{
demoMessageLog += "Additional focusHandler\n" +
" tracker:" + tracker + "\n" +
" event:" + event + "\n\n";
checkIfEventWasPassed(event);
updateDebugMessageOnScreenConsole();
});
viewer.addHandler("enter", function( event ){
demoMessageLog += "Additional enterHandler\n" +
" tracker:" + event.tracker + "\n" +
" position:" + event.position + "\n" +
" buttonDown:" + event.buttonDown + "\n" +
" buttonDownAny:" + event..buttonDownAny + "\n" +
" originalEvent:" + event.originalEvent + "\n\n";
checkIfEventWasPassed( event.originalEvent );
logMessage();
});
viewer.innerTracker.blurHandler = function(tracker, event)
{
demoMessageLog += "Altered version of original blurHandler\n" +
" tracker:" + tracker + "\n" +
" event:" + event + "\n\n";
checkIfEventWasPassed(event);
updateDebugMessageOnScreenConsole();
};
viewer.addHandler("blur", function(tracker, event)
{
demoMessageLog += "Additional blurHandler\n" +
" tracker:" + tracker + "\n" +
" event:" + event + "\n\n";
checkIfEventWasPassed(event);
updateDebugMessageOnScreenConsole();
viewer.addHandler("exit", function( event ){
demoMessageLog += "Additional exitHandler\n" +
" tracker:" + event.tracker + "\n" +
" position:" + event.position + "\n" +
" buttonDown:" + event.buttonDown + "\n" +
" buttonDownAny:" + event.buttonDownAny + "\n" +
" originalEvent:" + event.originalEvent + "\n\n";
checkIfEventWasPassed( event.originalEvent );
logMessage();
});
viewer.addHandler("focus", function( event ){
demoMessageLog += "Additional focusHandler\n" +
" tracker:" + event.tracker + "\n" +
" originalEvent:" + event.originalEvent + "\n\n";
checkIfEventWasPassed( event.originalEvent );
logMessage();
});
viewer.addHandler("blur", function( event ){
demoMessageLog += "Additional blurHandler\n" +
" tracker:" + event.tracker + "\n" +
" originalEvent:" + event.originalEvent + "\n\n";
checkIfEventWasPassed( event.originalEvent );
logMessage();
});
</script>