mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-25 14:46:10 +03:00
completed first pass at refactor of buttons.js, next will be mousetracker so we can attack some significant anti-patterns that spill over into places like buttons.js because the MouseTracker doesnt have an idiomatic constructor. It may also be worth applying the MouseTracker as a mixin to avoid the extra .tracker property indirection.
This commit is contained in:
parent
381763c19e
commit
345e5f3e6c
@ -1,12 +1,12 @@
|
|||||||
#OpenSeadragon build.properties
|
#OpenSeadragon build.properties
|
||||||
#TODO: how do you auto-increment build_id's with for every commit?
|
#TODO: how do you auto-increment build_id's with every commit?
|
||||||
# TRY: continuos integration
|
# TRY: continuos integration
|
||||||
# TRY: svn-hooks
|
# TRY: git-hooks
|
||||||
|
|
||||||
PROJECT: openseadragon
|
PROJECT: openseadragon
|
||||||
BUILD_MAJOR: 0
|
BUILD_MAJOR: 0
|
||||||
BUILD_MINOR: 8
|
BUILD_MINOR: 8
|
||||||
BUILD_ID: 13
|
BUILD_ID: 14
|
||||||
BUILD: ${PROJECT}.${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID}
|
BUILD: ${PROJECT}.${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID}
|
||||||
VERSION: ${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID}
|
VERSION: ${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* (c) 2010 OpenSeadragon
|
* (c) 2010 OpenSeadragon
|
||||||
* (c) 2010 CodePlex Foundation
|
* (c) 2010 CodePlex Foundation
|
||||||
*
|
*
|
||||||
* OpenSeadragon 0.8.13
|
* OpenSeadragon 0.8.14
|
||||||
* ----------------------------------------------------------------------------
|
* ----------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* License: New BSD License (BSD)
|
* License: New BSD License (BSD)
|
||||||
@ -782,7 +782,7 @@ $.Utils = new $.Utils();
|
|||||||
|
|
||||||
$.MouseTracker = function (elmt, clickTimeThreshold, clickDistThreshold) {
|
$.MouseTracker = function (elmt, clickTimeThreshold, clickDistThreshold) {
|
||||||
//Start Thatcher - TODO: remove local function definitions in favor of
|
//Start Thatcher - TODO: remove local function definitions in favor of
|
||||||
// - a global closre for MouseTracker so the number
|
// - a global closure for MouseTracker so the number
|
||||||
// - of Viewers has less memory impact. Also use
|
// - of Viewers has less memory impact. Also use
|
||||||
// - prototype pattern instead of Singleton pattern.
|
// - prototype pattern instead of Singleton pattern.
|
||||||
//End Thatcher
|
//End Thatcher
|
||||||
@ -2767,6 +2767,8 @@ $.ButtonState = {
|
|||||||
|
|
||||||
$.Button = function( options ) {
|
$.Button = function( options ) {
|
||||||
|
|
||||||
|
var _this = this;
|
||||||
|
|
||||||
$.EventHandler.call( this );
|
$.EventHandler.call( this );
|
||||||
|
|
||||||
this.tooltip = options.tooltip;
|
this.tooltip = options.tooltip;
|
||||||
@ -2853,50 +2855,48 @@ $.Button = function( options ) {
|
|||||||
styleDown.top = "";
|
styleDown.top = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
this.tracker.enterHandler = $.delegate( this, this._enterHandler );
|
//TODO - refactor mousetracer next to avoid this extension
|
||||||
this.tracker.exitHandler = $.delegate( this, this._exitHandler );
|
$.extend( this.tracker, {
|
||||||
this.tracker.pressHandler = $.delegate( this, this._pressHandler );
|
enterHandler: function(tracker, position, buttonDownElmt, buttonDownAny) {
|
||||||
this.tracker.releaseHandler = $.delegate( this, this._releaseHandler );
|
if ( buttonDownElmt ) {
|
||||||
this.tracker.clickHandler = $.delegate( this, this._clickHandler );
|
inTo( _this, $.ButtonState.DOWN );
|
||||||
|
_this.raiseEvent( "onEnter", _this );
|
||||||
|
} else if ( !buttonDownAny ) {
|
||||||
|
inTo( _this, $.ButtonState.HOVER );
|
||||||
|
}
|
||||||
|
},
|
||||||
|
exitHandler: function(tracker, position, buttonDownElmt, buttonDownAny) {
|
||||||
|
outTo( _this, $.ButtonState.GROUP );
|
||||||
|
if ( buttonDownElmt ) {
|
||||||
|
_this.raiseEvent( "onExit", _this );
|
||||||
|
}
|
||||||
|
},
|
||||||
|
pressHandler: function(tracker, position) {
|
||||||
|
inTo( _this, $.ButtonState.DOWN );
|
||||||
|
this.raiseEvent( "onPress", _this );
|
||||||
|
},
|
||||||
|
releaseHandler: function(tracker, position, insideElmtPress, insideElmtRelease) {
|
||||||
|
if ( insideElmtPress && insideElmtRelease ) {
|
||||||
|
outTo( _this, $.ButtonState.HOVER );
|
||||||
|
this.raiseEvent( "onRelease", _this );
|
||||||
|
} else if ( insideElmtPress ) {
|
||||||
|
outTo( _this, $.ButtonState.GROUP );
|
||||||
|
} else {
|
||||||
|
inTo( _this, $.ButtonState.HOVER );
|
||||||
|
}
|
||||||
|
},
|
||||||
|
clickHandler: function(tracker, position, quick, shift) {
|
||||||
|
if ( quick ) {
|
||||||
|
_this.raiseEvent("onClick", _this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
this.tracker.setTracking( true );
|
this.tracker.setTracking( true );
|
||||||
outTo( this, $.ButtonState.REST );
|
outTo( this, $.ButtonState.REST );
|
||||||
};
|
};
|
||||||
|
|
||||||
$.extend( $.Button.prototype, $.EventHandler.prototype, {
|
$.extend( $.Button.prototype, $.EventHandler.prototype, {
|
||||||
_enterHandler: function(tracker, position, buttonDownElmt, buttonDownAny) {
|
|
||||||
if ( buttonDownElmt ) {
|
|
||||||
inTo( this, $.ButtonState.DOWN );
|
|
||||||
this.raiseEvent( "onEnter", this );
|
|
||||||
} else if ( !buttonDownAny ) {
|
|
||||||
inTo( this, $.ButtonState.HOVER );
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_exitHandler: function(tracker, position, buttonDownElmt, buttonDownAny) {
|
|
||||||
outTo( this, $.ButtonState.GROUP );
|
|
||||||
if ( buttonDownElmt ) {
|
|
||||||
this.raiseEvent( "onExit", this );
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_pressHandler: function(tracker, position) {
|
|
||||||
inTo( this, $.ButtonState.DOWN );
|
|
||||||
this.raiseEvent( "onPress", this );
|
|
||||||
},
|
|
||||||
_releaseHandler: function(tracker, position, insideElmtPress, insideElmtRelease) {
|
|
||||||
if ( insideElmtPress && insideElmtRelease ) {
|
|
||||||
outTo( this, $.ButtonState.HOVER );
|
|
||||||
this.raiseEvent( "onRelease", this );
|
|
||||||
} else if ( insideElmtPress ) {
|
|
||||||
outTo( this, $.ButtonState.GROUP );
|
|
||||||
} else {
|
|
||||||
inTo( this, $.ButtonState.HOVER );
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_clickHandler: function(tracker, position, quick, shift) {
|
|
||||||
if ( quick ) {
|
|
||||||
this.raiseEvent("onClick", this);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
notifyGroupEnter: function() {
|
notifyGroupEnter: function() {
|
||||||
inTo( this, $.ButtonState.GROUP );
|
inTo( this, $.ButtonState.GROUP );
|
||||||
},
|
},
|
||||||
|
@ -10,6 +10,8 @@ $.ButtonState = {
|
|||||||
|
|
||||||
$.Button = function( options ) {
|
$.Button = function( options ) {
|
||||||
|
|
||||||
|
var _this = this;
|
||||||
|
|
||||||
$.EventHandler.call( this );
|
$.EventHandler.call( this );
|
||||||
|
|
||||||
this.tooltip = options.tooltip;
|
this.tooltip = options.tooltip;
|
||||||
@ -96,50 +98,48 @@ $.Button = function( options ) {
|
|||||||
styleDown.top = "";
|
styleDown.top = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
this.tracker.enterHandler = $.delegate( this, this._enterHandler );
|
//TODO - refactor mousetracer next to avoid this extension
|
||||||
this.tracker.exitHandler = $.delegate( this, this._exitHandler );
|
$.extend( this.tracker, {
|
||||||
this.tracker.pressHandler = $.delegate( this, this._pressHandler );
|
enterHandler: function(tracker, position, buttonDownElmt, buttonDownAny) {
|
||||||
this.tracker.releaseHandler = $.delegate( this, this._releaseHandler );
|
if ( buttonDownElmt ) {
|
||||||
this.tracker.clickHandler = $.delegate( this, this._clickHandler );
|
inTo( _this, $.ButtonState.DOWN );
|
||||||
|
_this.raiseEvent( "onEnter", _this );
|
||||||
|
} else if ( !buttonDownAny ) {
|
||||||
|
inTo( _this, $.ButtonState.HOVER );
|
||||||
|
}
|
||||||
|
},
|
||||||
|
exitHandler: function(tracker, position, buttonDownElmt, buttonDownAny) {
|
||||||
|
outTo( _this, $.ButtonState.GROUP );
|
||||||
|
if ( buttonDownElmt ) {
|
||||||
|
_this.raiseEvent( "onExit", _this );
|
||||||
|
}
|
||||||
|
},
|
||||||
|
pressHandler: function(tracker, position) {
|
||||||
|
inTo( _this, $.ButtonState.DOWN );
|
||||||
|
this.raiseEvent( "onPress", _this );
|
||||||
|
},
|
||||||
|
releaseHandler: function(tracker, position, insideElmtPress, insideElmtRelease) {
|
||||||
|
if ( insideElmtPress && insideElmtRelease ) {
|
||||||
|
outTo( _this, $.ButtonState.HOVER );
|
||||||
|
this.raiseEvent( "onRelease", _this );
|
||||||
|
} else if ( insideElmtPress ) {
|
||||||
|
outTo( _this, $.ButtonState.GROUP );
|
||||||
|
} else {
|
||||||
|
inTo( _this, $.ButtonState.HOVER );
|
||||||
|
}
|
||||||
|
},
|
||||||
|
clickHandler: function(tracker, position, quick, shift) {
|
||||||
|
if ( quick ) {
|
||||||
|
_this.raiseEvent("onClick", _this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
this.tracker.setTracking( true );
|
this.tracker.setTracking( true );
|
||||||
outTo( this, $.ButtonState.REST );
|
outTo( this, $.ButtonState.REST );
|
||||||
};
|
};
|
||||||
|
|
||||||
$.extend( $.Button.prototype, $.EventHandler.prototype, {
|
$.extend( $.Button.prototype, $.EventHandler.prototype, {
|
||||||
_enterHandler: function(tracker, position, buttonDownElmt, buttonDownAny) {
|
|
||||||
if ( buttonDownElmt ) {
|
|
||||||
inTo( this, $.ButtonState.DOWN );
|
|
||||||
this.raiseEvent( "onEnter", this );
|
|
||||||
} else if ( !buttonDownAny ) {
|
|
||||||
inTo( this, $.ButtonState.HOVER );
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_exitHandler: function(tracker, position, buttonDownElmt, buttonDownAny) {
|
|
||||||
outTo( this, $.ButtonState.GROUP );
|
|
||||||
if ( buttonDownElmt ) {
|
|
||||||
this.raiseEvent( "onExit", this );
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_pressHandler: function(tracker, position) {
|
|
||||||
inTo( this, $.ButtonState.DOWN );
|
|
||||||
this.raiseEvent( "onPress", this );
|
|
||||||
},
|
|
||||||
_releaseHandler: function(tracker, position, insideElmtPress, insideElmtRelease) {
|
|
||||||
if ( insideElmtPress && insideElmtRelease ) {
|
|
||||||
outTo( this, $.ButtonState.HOVER );
|
|
||||||
this.raiseEvent( "onRelease", this );
|
|
||||||
} else if ( insideElmtPress ) {
|
|
||||||
outTo( this, $.ButtonState.GROUP );
|
|
||||||
} else {
|
|
||||||
inTo( this, $.ButtonState.HOVER );
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_clickHandler: function(tracker, position, quick, shift) {
|
|
||||||
if ( quick ) {
|
|
||||||
this.raiseEvent("onClick", this);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
notifyGroupEnter: function() {
|
notifyGroupEnter: function() {
|
||||||
inTo( this, $.ButtonState.GROUP );
|
inTo( this, $.ButtonState.GROUP );
|
||||||
},
|
},
|
||||||
|
@ -8,45 +8,51 @@
|
|||||||
|
|
||||||
$.EventHandler.prototype = {
|
$.EventHandler.prototype = {
|
||||||
|
|
||||||
addHandler: function(id, handler) {
|
addHandler: function( id, handler ) {
|
||||||
var events = this.events[ id ];
|
var events = this.events[ id ];
|
||||||
if( !events ){
|
if( !events ){
|
||||||
this.events[ id ] = 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
|
//Start Thatcher - unneccessary indirection. Also, because events were
|
||||||
// - not actually being removed, we need to add the code
|
// - not actually being removed, we need to add the code
|
||||||
// - to do the removal ourselves. TODO
|
// - to do the removal ourselves. TODO
|
||||||
var evt = this.events[ id ];
|
var events = this.events[ id ];
|
||||||
if (!evt) return;
|
if ( !events ){
|
||||||
|
return;
|
||||||
|
}
|
||||||
//End Thatcher
|
//End Thatcher
|
||||||
},
|
},
|
||||||
|
|
||||||
getHandler: function(id) {
|
getHandler: function( id ) {
|
||||||
var evt = this.events[ id ];
|
var events = this.events[ id ];
|
||||||
if (!evt || !evt.length) return null;
|
if ( !events || !events.length ){
|
||||||
evt = evt.length === 1 ?
|
return null;
|
||||||
[evt[0]] :
|
}
|
||||||
Array.apply( null, evt );
|
events = events.length === 1 ?
|
||||||
return function(source, args) {
|
[ events[ 0 ] ] :
|
||||||
for (var i = 0, l = evt.length; i < l; i++) {
|
Array.apply( null, events );
|
||||||
evt[i](source, args);
|
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 );
|
var handler = this.getHandler( eventName );
|
||||||
|
|
||||||
if (handler) {
|
if ( handler ) {
|
||||||
if (!eventArgs) {
|
if ( !eventArgs ) {
|
||||||
eventArgs = new Object();
|
eventArgs = new Object();
|
||||||
}
|
}
|
||||||
|
|
||||||
handler(this, eventArgs);
|
handler( this, eventArgs );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
$.MouseTracker = function (elmt, clickTimeThreshold, clickDistThreshold) {
|
$.MouseTracker = function (elmt, clickTimeThreshold, clickDistThreshold) {
|
||||||
//Start Thatcher - TODO: remove local function definitions in favor of
|
//Start Thatcher - TODO: remove local function definitions in favor of
|
||||||
// - a global closre for MouseTracker so the number
|
// - a global closure for MouseTracker so the number
|
||||||
// - of Viewers has less memory impact. Also use
|
// - of Viewers has less memory impact. Also use
|
||||||
// - prototype pattern instead of Singleton pattern.
|
// - prototype pattern instead of Singleton pattern.
|
||||||
//End Thatcher
|
//End Thatcher
|
||||||
|
Loading…
Reference in New Issue
Block a user