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

@ -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( $ ){

View File

@ -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 ));