removed Job abstraction since it's constructor was only called in one place internally and the resulting object was private. removed file and reference in build.

This commit is contained in:
thatcher 2011-12-27 18:01:20 -05:00
parent 7854e14257
commit e591acfadb
5 changed files with 119 additions and 138 deletions

View File

@ -28,7 +28,6 @@
<file name="src/strings.js" />
<file name="src/point.js" />
<file name="src/profiler.js" />
<file name="src/job.js" />
<file name="src/imageloader.js" />
<file name="src/tilesource.js" />
<file name="src/dzitilesource.js" />

View File

@ -1337,7 +1337,7 @@ $.Viewer = function( options ) {
maxZoomPixelRatio: 2,
visibilityRatio: 0.5,
springStiffness: 5.0,
imageLoaderLimit: 2,
imageLoaderLimit: 0,
clickTimeThreshold: 200,
clickDistThreshold: 5,
zoomPerClick: 2.0,
@ -2391,53 +2391,8 @@ $.Profiler.prototype = {
(function( $ ){
$.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 = {
start: function() {
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.image.src = this.src;
}
};
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( $ ){
var TIMEOUT = 5000;
$.ImageLoader = function( imageLoaderLimit ) {
this.downloading = 0;
@ -2446,29 +2401,65 @@ $.ImageLoader = function( imageLoaderLimit ) {
$.ImageLoader.prototype = {
loadImage: function(src, callback) {
var _this = this;
if (this.downloading >= this.imageLoaderLimit) {
return false;
}
var _this = this,
loading = false,
image,
jobid,
complete;
var job = new $.Job(src, function(src, image){
_this.downloading--;
if (typeof (callback) == "function") {
try {
callback(image);
} catch (e) {
$.Debug.error(e.name + " while executing " + src +
" callback: " + e.message, e);
}
}
});
if ( !this.imageLoaderLimit || this.downloading < this.imageLoaderLimit ) {
this.downloading++;
job.start();
return true;
image = new Image();
complete = function( imagesrc ){
_this.downloading--;
if (typeof ( callback ) == "function") {
try {
callback( image );
} catch ( e ) {
$.Debug.error(
e.name + " while executing " + src +" callback: " + e.message,
e
);
}
}
};
image.onload = function(){
finish( image, complete, true );
};
image.onabort = image.onerror = function(){
finish( image, complete, false );
};
jobid = window.setTimeout( function(){
finish( image, complete, false, jobid );
}, TIMEOUT );
loading = true;
image.src = src;
}
return loading;
}
};
function finish( image, callback, successful, jobid ){
image.onload = null;
image.onabort = null;
image.onerror = null;
if ( jobid ) {
window.clearTimeout( jobid );
}
window.setTimeout( function() {
callback( image.src, successful ? image : null);
}, 1 );
};
}( OpenSeadragon ));

View File

@ -1,6 +1,9 @@
(function( $ ){
//TODO: make TIMEOUT configurable
var TIMEOUT = 5000;
$.ImageLoader = function( imageLoaderLimit ) {
this.downloading = 0;
this.imageLoaderLimit = imageLoaderLimit;
@ -8,29 +11,65 @@ $.ImageLoader = function( imageLoaderLimit ) {
$.ImageLoader.prototype = {
loadImage: function(src, callback) {
var _this = this;
if (this.downloading >= this.imageLoaderLimit) {
return false;
}
var _this = this,
loading = false,
image,
jobid,
complete;
var job = new $.Job(src, function(src, image){
_this.downloading--;
if (typeof (callback) == "function") {
try {
callback(image);
} catch (e) {
$.Debug.error(e.name + " while executing " + src +
" callback: " + e.message, e);
}
}
});
if ( !this.imageLoaderLimit || this.downloading < this.imageLoaderLimit ) {
this.downloading++;
job.start();
return true;
image = new Image();
complete = function( imagesrc ){
_this.downloading--;
if (typeof ( callback ) == "function") {
try {
callback( image );
} catch ( e ) {
$.Debug.error(
e.name + " while executing " + src +" callback: " + e.message,
e
);
}
}
};
image.onload = function(){
finish( image, complete, true );
};
image.onabort = image.onerror = function(){
finish( image, complete, false );
};
jobid = window.setTimeout( function(){
finish( image, complete, false, jobid );
}, TIMEOUT );
loading = true;
image.src = src;
}
return loading;
}
};
function finish( image, callback, successful, jobid ){
image.onload = null;
image.onabort = null;
image.onerror = null;
if ( jobid ) {
window.clearTimeout( jobid );
}
window.setTimeout( function() {
callback( image.src, successful ? image : null);
}, 1 );
};
}( OpenSeadragon ));

View File

@ -1,48 +0,0 @@
(function( $ ){
$.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 = {
start: function() {
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.image.src = this.src;
}
};
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 ));

View File

@ -63,7 +63,7 @@ $.Viewer = function( options ) {
maxZoomPixelRatio: 2,
visibilityRatio: 0.5,
springStiffness: 5.0,
imageLoaderLimit: 2,
imageLoaderLimit: 0,
clickTimeThreshold: 200,
clickDistThreshold: 5,
zoomPerClick: 2.0,