Revert "Bad sync"

This reverts commit 70a7e8090e13cc35b93e652d2bcd7f418af26fc1.
This commit is contained in:
Mark Salsbery 2013-08-26 15:47:21 -07:00
parent 04a0197dc7
commit f8ab315795
4 changed files with 694 additions and 707 deletions

View File

@ -36,7 +36,7 @@
/** /**
* For use by classes which want to support custom, non-browser events. * For use by classes which want to support custom, non-browser events.
* TODO: This is an awful name! This thing represents an "event source", * TODO: This is an aweful name! This thing represents an "event source",
* not an "event handler". PLEASE change the to EventSource. Also please * not an "event handler". PLEASE change the to EventSource. Also please
* change 'addHandler', 'removeHandler' and 'raiseEvent' to 'bind', * change 'addHandler', 'removeHandler' and 'raiseEvent' to 'bind',
* 'unbind', and 'trigger' respectively. Finally add a method 'one' which * 'unbind', and 'trigger' respectively. Finally add a method 'one' which
@ -55,15 +55,14 @@
* @function * @function
* @param {String} eventName - Name of event to register. * @param {String} eventName - Name of event to register.
* @param {Function} handler - Function to call when event is triggered. * @param {Function} handler - Function to call when event is triggered.
* @param {Object} optional userData - Arbitrary object to be passed to the handler.
*/ */
addHandler: function (eventName, handler, userData) { addHandler: function( eventName, handler ) {
var events = this.events[ eventName ]; var events = this.events[ eventName ];
if( !events ){ if( !events ){
this.events[ eventName ] = events = []; this.events[ eventName ] = events = [];
} }
if( handler && $.isFunction( handler ) ){ if( handler && $.isFunction( handler ) ){
events[events.length] = { handler: handler, userData: userData || null }; events[ events.length ] = handler;
} }
}, },
@ -82,7 +81,7 @@
} }
if( $.isArray( events ) ){ if( $.isArray( events ) ){
for( i = 0; i < events.length; i++ ){ for( i = 0; i < events.length; i++ ){
if (events[i].handler !== handler) { if( events[ i ] !== handler ){
handlers.push( events[ i ] ); handlers.push( events[ i ] );
} }
} }
@ -108,7 +107,7 @@
}, },
/** /**
* Retrieve the list of all handlers registered for a given event. * Retrive the list of all handlers registered for a given event.
* @function * @function
* @param {String} eventName - Name of event to get handlers for. * @param {String} eventName - Name of event to get handlers for.
*/ */
@ -125,8 +124,7 @@
length = events.length; length = events.length;
for ( i = 0; i < length; i++ ) { for ( i = 0; i < length; i++ ) {
if( events[ i ] ){ if( events[ i ] ){
args.userData = events[i].userData; events[ i ]( source, args );
events[i].handler(source, args);
} }
} }
}; };

View File

@ -71,16 +71,8 @@
//clean up the levels to make sure we support all formats //clean up the levels to make sure we support all formats
options.levels = filterFiles( options.levels ); options.levels = filterFiles( options.levels );
if (options.levels.length > 0) {
width = options.levels[ options.levels.length - 1 ].width; width = options.levels[ options.levels.length - 1 ].width;
height = options.levels[ options.levels.length - 1 ].height; height = options.levels[ options.levels.length - 1 ].height;
}
else {
width = 0;
height = 0;
$.console.error("No supported image formats found");
}
$.extend( true, options, { $.extend( true, options, {
width: width, width: width,
@ -88,7 +80,7 @@
tileSize: Math.max( height, width ), tileSize: Math.max( height, width ),
tileOverlap: 0, tileOverlap: 0,
minLevel: 0, minLevel: 0,
maxLevel: options.levels.length > 0 ? options.levels.length - 1 : 0 maxLevel: options.levels.length - 1
}); });
$.TileSource.apply( this, [ options ] ); $.TileSource.apply( this, [ options ] );
@ -149,7 +141,7 @@
*/ */
getLevelScale: function( level ) { getLevelScale: function( level ) {
var levelScale = NaN; var levelScale = NaN;
if (this.levels.length > 0 && level >= this.minLevel && level <= this.maxLevel) { if ( level >= this.minLevel && level <= this.maxLevel ){
levelScale = levelScale =
this.levels[ level ].width / this.levels[ level ].width /
this.levels[ this.maxLevel ].width; this.levels[ this.maxLevel ].width;
@ -196,7 +188,7 @@
*/ */
getTileUrl: function( level, x, y ) { getTileUrl: function( level, x, y ) {
var url = null; var url = null;
if (this.levels.length > 0 && level >= this.minLevel && level <= this.maxLevel) { if( level >= this.minLevel && level <= this.maxLevel ){
url = this.levels[ level ].url; url = this.levels[ level ].url;
} }
return url; return url;
@ -231,9 +223,6 @@
height: Number( file.height ) height: Number( file.height )
}); });
} }
else {
$.console.error('Unsupported image format: %s', file.url ? file.url : '<no URL>');
}
} }
return filtered.sort(function(a,b){ return filtered.sort(function(a,b){

View File

@ -117,8 +117,8 @@
for( i = 0; i < arguments.length; i++ ){ for( i = 0; i < arguments.length; i++ ){
if( $.isFunction( arguments[i] ) ){ if( $.isFunction( arguments[i] ) ){
callback = arguments[ i ]; callback = arguments[ i ];
this.addHandler('ready', function (placeHolderSource, placeHolderArgs) { this.addHandler( 'ready', function( placeHolderSource, readySource ){
callback(placeHolderArgs.tileSource); callback( readySource );
}); });
//only one callback per constructor //only one callback per constructor
break; break;
@ -301,7 +301,7 @@
options = $TileSource.prototype.configure.apply( _this, [ data, url ]); options = $TileSource.prototype.configure.apply( _this, [ data, url ]);
readySource = new $TileSource( options ); readySource = new $TileSource( options );
_this.ready = true; _this.ready = true;
_this.raiseEvent('ready', { tileSource: readySource }); _this.raiseEvent( 'ready', readySource );
}; };
if( url.match(/\.js$/) ){ if( url.match(/\.js$/) ){

View File

@ -1463,7 +1463,7 @@ function onCanvasDrag( tracker, position, delta, shift ) {
this.viewport.applyConstraints(); this.viewport.applyConstraints();
} }
} }
this.raiseEvent( 'canvas-drag', { this.raiseEvent( 'canvas-click', {
tracker: tracker, tracker: tracker,
position: position, position: position,
delta: delta, delta: delta,