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/strings.js" />
<file name="src/point.js" /> <file name="src/point.js" />
<file name="src/profiler.js" /> <file name="src/profiler.js" />
<file name="src/job.js" />
<file name="src/imageloader.js" /> <file name="src/imageloader.js" />
<file name="src/tilesource.js" /> <file name="src/tilesource.js" />
<file name="src/dzitilesource.js" /> <file name="src/dzitilesource.js" />

View File

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

View File

@ -1,6 +1,9 @@
(function( $ ){ (function( $ ){
//TODO: make TIMEOUT configurable
var TIMEOUT = 5000;
$.ImageLoader = function( imageLoaderLimit ) { $.ImageLoader = function( imageLoaderLimit ) {
this.downloading = 0; this.downloading = 0;
this.imageLoaderLimit = imageLoaderLimit; this.imageLoaderLimit = imageLoaderLimit;
@ -8,29 +11,65 @@ $.ImageLoader = function( imageLoaderLimit ) {
$.ImageLoader.prototype = { $.ImageLoader.prototype = {
loadImage: function(src, callback) { loadImage: function(src, callback) {
var _this = this; var _this = this,
if (this.downloading >= this.imageLoaderLimit) { loading = false,
return false; image,
} jobid,
complete;
var job = new $.Job(src, function(src, image){ if ( !this.imageLoaderLimit || this.downloading < this.imageLoaderLimit ) {
this.downloading++;
image = new Image();
complete = function( imagesrc ){
_this.downloading--; _this.downloading--;
if (typeof ( callback ) == "function") { if (typeof ( callback ) == "function") {
try { try {
callback( image ); callback( image );
} catch ( e ) { } catch ( e ) {
$.Debug.error(e.name + " while executing " + src + $.Debug.error(
" callback: " + e.message, e); e.name + " while executing " + src +" callback: " + e.message,
e
);
} }
} }
}); };
this.downloading++; image.onload = function(){
job.start(); finish( image, complete, true );
};
return 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 )); }( 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, maxZoomPixelRatio: 2,
visibilityRatio: 0.5, visibilityRatio: 0.5,
springStiffness: 5.0, springStiffness: 5.0,
imageLoaderLimit: 2, imageLoaderLimit: 0,
clickTimeThreshold: 200, clickTimeThreshold: 200,
clickDistThreshold: 5, clickDistThreshold: 5,
zoomPerClick: 2.0, zoomPerClick: 2.0,