mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-25 14:46:10 +03:00
removed psuedo-privacy anti-patterns from job.js in favor of simple pinning and public properties.
This commit is contained in:
parent
de14271399
commit
f482c0fb56
@ -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( $ ){
|
||||
|
77
src/job.js
77
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 ));
|
||||
|
Loading…
Reference in New Issue
Block a user