Merge pull request #237 from msalsbery/Event-Names-Normalize

Event names normalize
This commit is contained in:
iangilman 2013-10-02 09:46:48 -07:00
commit 5ce3da2548
7 changed files with 43 additions and 37 deletions

View File

@ -5,6 +5,16 @@ OPENSEADRAGON CHANGELOG
* 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"
* Button "onPress" changed to "press"
* Button "onRelease" changed to "release"
* Button "onClick" changed to "click"
* Button "onEnter" changed to "enter"
* Button "onExit" changed to "exit"
* Button "onFocus" changed to "focus"
* Button "onBlur" changed to "blur"
* 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)

View File

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

View File

@ -36,12 +36,8 @@
/**
* For use by classes which want to support custom, non-browser events.
* TODO: This is an awful name! This thing represents an "event source",
* not an "event handler". PLEASE change the to EventSource. Also please
* change 'addHandler', 'removeHandler' and 'raiseEvent' to 'bind',
* 'unbind', and 'trigger' respectively. Finally add a method 'one' which
* automatically unbinds a listener after the first triggered event that
* matches.
* TODO: Add a method 'one' which automatically unbinds a listener after
* the first triggered event that matches.
* @class
*/
$.EventSource = function() {

View File

@ -46,7 +46,7 @@ var I18N = {
Security: "It looks like a security restriction stopped us from " +
"loading this Deep Zoom Image.",
Status: "This space unintentionally left blank ({0} {1}).",
"Open-Failed": "Unable to open {0}: {1}"
OpenFailed: "Unable to open {0}: {1}"
},
Tooltips: {

View File

@ -173,7 +173,7 @@ $.Viewer = function( options ) {
$.EventSource.call( this );
this.addHandler( 'open-failed', function (source, args) {
var msg = $.getString( "Errors.Open-Failed", args.source, args.message);
var msg = $.getString( "Errors.OpenFailed", args.source, args.message);
_this._showMessage( msg );
});
@ -1589,7 +1589,7 @@ function updateOnce( viewer ) {
}
if ( !THIS[ viewer.hash ].animating && animated ) {
viewer.raiseEvent( "animationstart" );
viewer.raiseEvent( "animation-start" );
abortControlsAutoHide( viewer );
}
@ -1608,7 +1608,7 @@ function updateOnce( viewer ) {
}
if ( THIS[ viewer.hash ].animating && !animated ) {
viewer.raiseEvent( "animationfinish" );
viewer.raiseEvent( "animation-finish" );
if ( !THIS[ viewer.hash ].mouseInside ) {
beginControlsAutoHide( viewer );

View File

@ -73,12 +73,12 @@
equal(viewport.getZoom(), 1, 'We start out unzoomed');
var zoomHandler = function() {
viewer.removeHandler('animationfinish', zoomHandler);
viewer.removeHandler('animation-finish', zoomHandler);
equal(viewport.getZoom(), 2, 'Zoomed correctly');
start();
};
viewer.addHandler('animationfinish', zoomHandler);
viewer.addHandler('animation-finish', zoomHandler);
viewport.zoomTo(2);
});
viewer.open('/test/data/testpattern.dzi');
@ -93,13 +93,13 @@
ok(center.x === 0.5 && center.y === 0.5, 'We start out unpanned');
var panHandler = function() {
viewer.removeHandler('animationfinish', panHandler);
viewer.removeHandler('animation-finish', panHandler);
center = viewport.getCenter();
ok(center.x === 0.1 && center.y === 0.1, 'Panned correctly');
start();
};
viewer.addHandler('animationfinish', panHandler);
viewer.addHandler('animation-finish', panHandler);
viewport.panTo(new OpenSeadragon.Point(0.1, 0.1));
});
@ -119,25 +119,25 @@
var viewport = viewer.viewport,
center = viewport.getCenter();
viewer.removeHandler('animationfinish', stage1);
viewer.removeHandler('animation-finish', stage1);
ok(center.x !== 0.5 && center.y !== 0.5, 'We start out panned');
notEqual(viewport.getZoom(), 1, 'We start out zoomed');
var homeHandler = function() {
viewer.removeHandler('animationfinish', homeHandler);
viewer.removeHandler('animation-finish', homeHandler);
center = viewport.getCenter();
ok(center.x === 0.5 && center.y === 0.5, 'We end up unpanned');
equal(viewport.getZoom(), 1, 'We end up unzoomed');
start();
};
viewer.addHandler('animationfinish', homeHandler);
viewer.addHandler('animation-finish', homeHandler);
viewport.goHome(true);
}
viewer.addHandler("open", opener);
viewer.addHandler("animationfinish", stage1);
viewer.addHandler("animation-finish", stage1);
viewer.open('/test/data/testpattern.dzi');
});
@ -152,14 +152,14 @@
equal(viewport.getZoom(), 1, 'We start out unzoomed');
var clickHandler = function() {
viewer.removeHandler('animationfinish', clickHandler);
viewer.removeHandler('animation-finish', clickHandler);
center = viewport.getCenter();
ok(center.x > 0.37 && center.x < 0.38 && center.y > 0.37 && center.y < 0.38, 'Panned correctly');
equal(viewport.getZoom(), 2, 'Zoomed correctly');
start();
};
viewer.addHandler('animationfinish', clickHandler);
viewer.addHandler('animation-finish', clickHandler);
Util.simulateViewerClickWithDrag( {
viewer: viewer,
widthFactor: 0.25,

View File

@ -15,7 +15,7 @@
});
test("getStringWithPlaceholders", function() {
equal(OpenSeadragon.getString("Errors.Open-Failed", "foo", "bar"),
equal(OpenSeadragon.getString("Errors.OpenFailed", "foo", "bar"),
"Unable to open foo: bar",
"String placeholder replacement");
});