removed initialize anti-pattern in favor of using constructor. combined Button constructor arguments into idiomatic single options object

This commit is contained in:
thatcher 2011-12-14 17:40:22 -05:00
parent 7f7589e939
commit d7de748434
4 changed files with 150 additions and 158 deletions

View File

@ -6,7 +6,7 @@
PROJECT: openseadragon
BUILD_MAJOR: 0
BUILD_MINOR: 8
BUILD_ID: 10
BUILD_ID: 11
BUILD: ${PROJECT}.${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID}
VERSION: ${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID}

View File

@ -3,7 +3,7 @@
* (c) 2010 OpenSeadragon
* (c) 2010 CodePlex Foundation
*
* OpenSeadragon 0.8.10
* OpenSeadragon 0.8.11
* ----------------------------------------------------------------------------
*
* License: New BSD License (BSD)
@ -1225,8 +1225,7 @@ $.NavControl.prototype = {
srcRest: this._resolveUrl(navImages.zoomIn.REST),
srcGroup: this._resolveUrl(navImages.zoomIn.GROUP),
srcHover: this._resolveUrl(navImages.zoomIn.HOVER),
srcDown: this._resolveUrl(navImages.zoomIn.DOWN)
},{
srcDown: this._resolveUrl(navImages.zoomIn.DOWN),
onPress: beginZoomingInHandler,
onRelease: endZoomingHandler,
onClick: doSingleZoomInHandler,
@ -1239,8 +1238,7 @@ $.NavControl.prototype = {
srcRest: this._resolveUrl(navImages.zoomOut.REST),
srcGroup: this._resolveUrl(navImages.zoomOut.GROUP),
srcHover: this._resolveUrl(navImages.zoomOut.HOVER),
srcDown: this._resolveUrl(navImages.zoomOut.DOWN)
}, {
srcDown: this._resolveUrl(navImages.zoomOut.DOWN),
onPress: beginZoomingOutHandler,
onRelease: endZoomingHandler,
onClick: doSingleZoomOutHandler,
@ -1253,8 +1251,7 @@ $.NavControl.prototype = {
srcRest: this._resolveUrl(navImages.home.REST),
srcGroup: this._resolveUrl(navImages.home.GROUP),
srcHover: this._resolveUrl(navImages.home.HOVER),
srcDown: this._resolveUrl(navImages.home.DOWN)
},{
srcDown: this._resolveUrl(navImages.home.DOWN),
onRelease: onHomeHandler
});
var fullPage = new $.Button({
@ -1263,8 +1260,7 @@ $.NavControl.prototype = {
srcRest: this._resolveUrl(navImages.fullpage.REST),
srcGroup: this._resolveUrl(navImages.fullpage.GROUP),
srcHover: this._resolveUrl(navImages.fullpage.HOVER),
srcDown: this._resolveUrl(navImages.fullpage.DOWN)
},{
srcDown: this._resolveUrl(navImages.fullpage.DOWN),
onRelease: onFullPageHandler
});
this._group = new $.ButtonGroup({
@ -2809,38 +2805,36 @@ $.ButtonState = {
DOWN: 3
};
$.Button = function( properties, events ) {
$.Button = function( options ) {
this._tooltip = properties.tooltip;
this._srcRest = properties.srcRest;
this._srcGroup = properties.srcGroup;
this._srcHover = properties.srcHover;
this._srcDown = properties.srcDown;
this._button = properties.button;
this.config = properties.config;
this.initialize( events );
};
$.Button.prototype = {
initialize: function( events ) {
this._tooltip = options.tooltip;
this._srcRest = options.srcRest;
this._srcGroup = options.srcGroup;
this._srcHover = options.srcHover;
this._srcDown = options.srcDown;
this._button = options.button;
this.config = options.config;
this._events = new $.EventHandlerList();
if (events.onPress != undefined)
this.add_onPress(events.onPress);
if (events.onRelease != undefined)
this.add_onRelease(events.onRelease);
if (events.onClick != undefined)
this.add_onClick(events.onClick);
if (events.onEnter != undefined)
this.add_onEnter(events.onEnter);
if (events.onExit != undefined)
this.add_onExit(events.onExit);
if ( options.onPress != undefined )
this.add_onPress( options.onPress );
if ( options.onRelease != undefined )
this.add_onRelease( options.onRelease );
if ( options.onClick != undefined )
this.add_onClick( options.onClick );
if ( options.onEnter != undefined )
this.add_onEnter( options.onEnter );
if ( options.onExit != undefined )
this.add_onExit( options.onExit );
this._button = $.Utils.makeNeutralElement("span");
this._currentState = $.ButtonState.GROUP;
this._tracker = new $.MouseTracker(this._button, this.config.clickTimeThreshold, this.config.clickDistThreshold);
this._tracker = new $.MouseTracker(
this._button,
this.config.clickTimeThreshold,
this.config.clickDistThreshold
);
this._imgRest = $.Utils.makeTransparentImage(this._srcRest);
this._imgGroup = $.Utils.makeTransparentImage(this._srcGroup);
this._imgHover = $.Utils.makeTransparentImage(this._srcHover);
@ -2883,7 +2877,9 @@ $.Button.prototype = {
this._tracker.setTracking( true );
this._outTo( $.ButtonState.REST );
},
};
$.Button.prototype = {
_scheduleFade: function() {
window.setTimeout($.delegate(this, this._updateFade), 20);
},

View File

@ -8,38 +8,36 @@ $.ButtonState = {
DOWN: 3
};
$.Button = function( properties, events ) {
$.Button = function( options ) {
this._tooltip = properties.tooltip;
this._srcRest = properties.srcRest;
this._srcGroup = properties.srcGroup;
this._srcHover = properties.srcHover;
this._srcDown = properties.srcDown;
this._button = properties.button;
this.config = properties.config;
this.initialize( events );
};
$.Button.prototype = {
initialize: function( events ) {
this._tooltip = options.tooltip;
this._srcRest = options.srcRest;
this._srcGroup = options.srcGroup;
this._srcHover = options.srcHover;
this._srcDown = options.srcDown;
this._button = options.button;
this.config = options.config;
this._events = new $.EventHandlerList();
if (events.onPress != undefined)
this.add_onPress(events.onPress);
if (events.onRelease != undefined)
this.add_onRelease(events.onRelease);
if (events.onClick != undefined)
this.add_onClick(events.onClick);
if (events.onEnter != undefined)
this.add_onEnter(events.onEnter);
if (events.onExit != undefined)
this.add_onExit(events.onExit);
if ( options.onPress != undefined )
this.add_onPress( options.onPress );
if ( options.onRelease != undefined )
this.add_onRelease( options.onRelease );
if ( options.onClick != undefined )
this.add_onClick( options.onClick );
if ( options.onEnter != undefined )
this.add_onEnter( options.onEnter );
if ( options.onExit != undefined )
this.add_onExit( options.onExit );
this._button = $.Utils.makeNeutralElement("span");
this._currentState = $.ButtonState.GROUP;
this._tracker = new $.MouseTracker(this._button, this.config.clickTimeThreshold, this.config.clickDistThreshold);
this._tracker = new $.MouseTracker(
this._button,
this.config.clickTimeThreshold,
this.config.clickDistThreshold
);
this._imgRest = $.Utils.makeTransparentImage(this._srcRest);
this._imgGroup = $.Utils.makeTransparentImage(this._srcGroup);
this._imgHover = $.Utils.makeTransparentImage(this._srcHover);
@ -82,7 +80,9 @@ $.Button.prototype = {
this._tracker.setTracking( true );
this._outTo( $.ButtonState.REST );
},
};
$.Button.prototype = {
_scheduleFade: function() {
window.setTimeout($.delegate(this, this._updateFade), 20);
},

View File

@ -31,8 +31,7 @@ $.NavControl.prototype = {
srcRest: this._resolveUrl(navImages.zoomIn.REST),
srcGroup: this._resolveUrl(navImages.zoomIn.GROUP),
srcHover: this._resolveUrl(navImages.zoomIn.HOVER),
srcDown: this._resolveUrl(navImages.zoomIn.DOWN)
},{
srcDown: this._resolveUrl(navImages.zoomIn.DOWN),
onPress: beginZoomingInHandler,
onRelease: endZoomingHandler,
onClick: doSingleZoomInHandler,
@ -45,8 +44,7 @@ $.NavControl.prototype = {
srcRest: this._resolveUrl(navImages.zoomOut.REST),
srcGroup: this._resolveUrl(navImages.zoomOut.GROUP),
srcHover: this._resolveUrl(navImages.zoomOut.HOVER),
srcDown: this._resolveUrl(navImages.zoomOut.DOWN)
}, {
srcDown: this._resolveUrl(navImages.zoomOut.DOWN),
onPress: beginZoomingOutHandler,
onRelease: endZoomingHandler,
onClick: doSingleZoomOutHandler,
@ -59,8 +57,7 @@ $.NavControl.prototype = {
srcRest: this._resolveUrl(navImages.home.REST),
srcGroup: this._resolveUrl(navImages.home.GROUP),
srcHover: this._resolveUrl(navImages.home.HOVER),
srcDown: this._resolveUrl(navImages.home.DOWN)
},{
srcDown: this._resolveUrl(navImages.home.DOWN),
onRelease: onHomeHandler
});
var fullPage = new $.Button({
@ -69,8 +66,7 @@ $.NavControl.prototype = {
srcRest: this._resolveUrl(navImages.fullpage.REST),
srcGroup: this._resolveUrl(navImages.fullpage.GROUP),
srcHover: this._resolveUrl(navImages.fullpage.HOVER),
srcDown: this._resolveUrl(navImages.fullpage.DOWN)
},{
srcDown: this._resolveUrl(navImages.fullpage.DOWN),
onRelease: onFullPageHandler
});
this._group = new $.ButtonGroup({