diff --git a/openseadragon.js b/openseadragon.js index 5906c54c..fc7caaa9 100644 --- a/openseadragon.js +++ b/openseadragon.js @@ -2425,49 +2425,58 @@ $.Profiler.prototype = { (function( $ ){ -$.Job = function(src, callback) { - this._image = null; - this._timeout = null; - this._src = src; - this._callback = callback; +$.Job = function( src, callback ) { + this.image = null; + this.timeout = null; + this.src = src; + this.callback = callback; + //TODO: make TIMEOUT configurable this.TIMEOUT = 5000; }; $.Job.prototype = { - _finish: function(success) { - this._image.onload = null; - this._image.onabort = null; - this._image.onerror = null; - - - if (this._timeout) { - window.clearTimeout(this._timeout); - } - - var image = this._image; - var callback = this._callback; - window.setTimeout(function() { - callback(this._src, success ? image : null); - }, 1); - }, - _onloadHandler: function() { - this._finish(true); - }, - _onerrorHandler: function() { - this._finish(false); - }, start: function() { - this._image = new Image(); - this._image.onload = $.delegate(this, this._onloadHandler); - this._image.onabort = $.delegate(this, this._onerrorHandler); - this._image.onerror = $.delegate(this, this._onerrorHandler); + var _this = this; + this.image = new Image(); + this.image.onload = function(){ + finish( _this, true ); + }; + this.image.onabort = this.image.onerror = function(){ + finish( _this, false ); + }; + this.timeout = window.setTimeout( function(){ + onerror( _this ); + }, this.TIMEOUT ); - this._timeout = window.setTimeout($.delegate(this, this._onerrorHandler), this.TIMEOUT); - - this._image.src = this._src; + this.image.src = this.src; } }; +function onload( job ){ + finish( job, true ); +}; + +function onerror( job ){ + finish( job, false ) +}; + +function finish( job, success ){ + var image = job.image, + callback = job.callback; + + image.onload = null; + image.onabort = null; + image.onerror = null; + + if ( job.timeout ) { + window.clearTimeout( job.timeout ); + } + window.setTimeout( function() { + callback(job.src, success ? image : null); + }, 1 ); + +}; + }( OpenSeadragon )); (function( $ ){ diff --git a/src/job.js b/src/job.js index e9451dd7..d253390c 100644 --- a/src/job.js +++ b/src/job.js @@ -1,47 +1,56 @@ (function( $ ){ -$.Job = function(src, callback) { - this._image = null; - this._timeout = null; - this._src = src; - this._callback = callback; +$.Job = function( src, callback ) { + this.image = null; + this.timeout = null; + this.src = src; + this.callback = callback; + //TODO: make TIMEOUT configurable this.TIMEOUT = 5000; }; $.Job.prototype = { - _finish: function(success) { - this._image.onload = null; - this._image.onabort = null; - this._image.onerror = null; - - - if (this._timeout) { - window.clearTimeout(this._timeout); - } - - var image = this._image; - var callback = this._callback; - window.setTimeout(function() { - callback(this._src, success ? image : null); - }, 1); - }, - _onloadHandler: function() { - this._finish(true); - }, - _onerrorHandler: function() { - this._finish(false); - }, start: function() { - this._image = new Image(); - this._image.onload = $.delegate(this, this._onloadHandler); - this._image.onabort = $.delegate(this, this._onerrorHandler); - this._image.onerror = $.delegate(this, this._onerrorHandler); + var _this = this; + this.image = new Image(); + this.image.onload = function(){ + finish( _this, true ); + }; + this.image.onabort = this.image.onerror = function(){ + finish( _this, false ); + }; + this.timeout = window.setTimeout( function(){ + onerror( _this ); + }, this.TIMEOUT ); - this._timeout = window.setTimeout($.delegate(this, this._onerrorHandler), this.TIMEOUT); - - this._image.src = this._src; + this.image.src = this.src; } }; +function onload( job ){ + finish( job, true ); +}; + +function onerror( job ){ + finish( job, false ) +}; + +function finish( job, success ){ + var image = job.image, + callback = job.callback; + + image.onload = null; + image.onabort = null; + image.onerror = null; + + if ( job.timeout ) { + window.clearTimeout( job.timeout ); + } + window.setTimeout( function() { + callback(job.src, success ? image : null); + }, 1 ); + +}; + }( OpenSeadragon ));