removed psuedo-privacy anti-patterns from job.js in favor of simple pinning and public properties.

This commit is contained in:
thatcher 2011-12-13 19:10:27 -05:00
parent de14271399
commit f482c0fb56
2 changed files with 86 additions and 68 deletions

View File

@ -2426,48 +2426,57 @@ $.Profiler.prototype = {
(function( $ ){ (function( $ ){
$.Job = function( src, callback ) { $.Job = function( src, callback ) {
this._image = null; this.image = null;
this._timeout = null; this.timeout = null;
this._src = src; this.src = src;
this._callback = callback; this.callback = callback;
//TODO: make TIMEOUT configurable
this.TIMEOUT = 5000; this.TIMEOUT = 5000;
}; };
$.Job.prototype = { $.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() { start: function() {
this._image = new Image(); var _this = this;
this._image.onload = $.delegate(this, this._onloadHandler); this.image = new Image();
this._image.onabort = $.delegate(this, this._onerrorHandler); this.image.onload = function(){
this._image.onerror = $.delegate(this, this._onerrorHandler); 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 )); }( OpenSeadragon ));
(function( $ ){ (function( $ ){

View File

@ -2,46 +2,55 @@
(function( $ ){ (function( $ ){
$.Job = function( src, callback ) { $.Job = function( src, callback ) {
this._image = null; this.image = null;
this._timeout = null; this.timeout = null;
this._src = src; this.src = src;
this._callback = callback; this.callback = callback;
//TODO: make TIMEOUT configurable
this.TIMEOUT = 5000; this.TIMEOUT = 5000;
}; };
$.Job.prototype = { $.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() { start: function() {
this._image = new Image(); var _this = this;
this._image.onload = $.delegate(this, this._onloadHandler); this.image = new Image();
this._image.onabort = $.delegate(this, this._onerrorHandler); this.image.onload = function(){
this._image.onerror = $.delegate(this, this._onerrorHandler); 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 )); }( OpenSeadragon ));