diff --git a/openseadragon.js b/openseadragon.js index 540f5e6c..d3de1584 100644 --- a/openseadragon.js +++ b/openseadragon.js @@ -210,45 +210,51 @@ OpenSeadragon = window.OpenSeadragon || (function(){ $.EventHandler.prototype = { - addHandler: function(id, handler) { + addHandler: function( id, handler ) { var events = this.events[ id ]; if( !events ){ this.events[ id ] = events = []; } - events[events.length] = handler; + events[ events.length ] = handler; }, - removeHandler: function(id, handler) { + removeHandler: function( id, handler ) { //Start Thatcher - unneccessary indirection. Also, because events were // - not actually being removed, we need to add the code // - to do the removal ourselves. TODO - var evt = this.events[ id ]; - if (!evt) return; + var events = this.events[ id ]; + if ( !events ){ + return; + } //End Thatcher }, - getHandler: function(id) { - var evt = this.events[ id ]; - if (!evt || !evt.length) return null; - evt = evt.length === 1 ? - [evt[0]] : - Array.apply( null, evt ); - return function(source, args) { - for (var i = 0, l = evt.length; i < l; i++) { - evt[i](source, args); + getHandler: function( id ) { + var events = this.events[ id ]; + if ( !events || !events.length ){ + return null; + } + events = events.length === 1 ? + [ events[ 0 ] ] : + Array.apply( null, events ); + return function( source, args ) { + var i, + l = events.length; + for ( i = 0; i < l; i++ ) { + events[ i ]( source, args ); } }; }, - raiseEvent: function(eventName, eventArgs) { + raiseEvent: function( eventName, eventArgs ) { var handler = this.getHandler( eventName ); - if (handler) { - if (!eventArgs) { + if ( handler ) { + if ( !eventArgs ) { eventArgs = new Object(); } - handler(this, eventArgs); + handler( this, eventArgs ); } } }; @@ -2873,12 +2879,12 @@ $.Button = function( options ) { }, pressHandler: function(tracker, position) { inTo( _this, $.ButtonState.DOWN ); - this.raiseEvent( "onPress", _this ); + _this.raiseEvent( "onPress", _this ); }, releaseHandler: function(tracker, position, insideElmtPress, insideElmtRelease) { if ( insideElmtPress && insideElmtRelease ) { outTo( _this, $.ButtonState.HOVER ); - this.raiseEvent( "onRelease", _this ); + _this.raiseEvent( "onRelease", _this ); } else if ( insideElmtPress ) { outTo( _this, $.ButtonState.GROUP ); } else { @@ -2970,8 +2976,8 @@ function outTo( button, newState ) { } if ( newState <= $.ButtonState.GROUP && button.currentState == $.ButtonState.HOVER ) { - this.imgHover.style.visibility = "hidden"; - this.currentState = $.ButtonState.GROUP; + button.imgHover.style.visibility = "hidden"; + button.currentState = $.ButtonState.GROUP; } if ( button.newState <= $.ButtonState.REST && button.currentState == $.ButtonState.GROUP ) { diff --git a/src/button.js b/src/button.js index 3a214530..de8d41f5 100644 --- a/src/button.js +++ b/src/button.js @@ -116,12 +116,12 @@ $.Button = function( options ) { }, pressHandler: function(tracker, position) { inTo( _this, $.ButtonState.DOWN ); - this.raiseEvent( "onPress", _this ); + _this.raiseEvent( "onPress", _this ); }, releaseHandler: function(tracker, position, insideElmtPress, insideElmtRelease) { if ( insideElmtPress && insideElmtRelease ) { outTo( _this, $.ButtonState.HOVER ); - this.raiseEvent( "onRelease", _this ); + _this.raiseEvent( "onRelease", _this ); } else if ( insideElmtPress ) { outTo( _this, $.ButtonState.GROUP ); } else { @@ -213,8 +213,8 @@ function outTo( button, newState ) { } if ( newState <= $.ButtonState.GROUP && button.currentState == $.ButtonState.HOVER ) { - this.imgHover.style.visibility = "hidden"; - this.currentState = $.ButtonState.GROUP; + button.imgHover.style.visibility = "hidden"; + button.currentState = $.ButtonState.GROUP; } if ( button.newState <= $.ButtonState.REST && button.currentState == $.ButtonState.GROUP ) {