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,
@ -2390,54 +2390,9 @@ $.Profiler.prototype = {
}( OpenSeadragon ));
(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,31 +2401,67 @@ $.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;
if ( !this.imageLoaderLimit || this.downloading < this.imageLoaderLimit ) {
this.downloading++;
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;
}
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);
}
}
});
this.downloading++;
job.start();
return true;
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 ));
(function( $ ){

View File

@ -1,5 +1,8 @@
(function( $ ){
//TODO: make TIMEOUT configurable
var TIMEOUT = 5000;
$.ImageLoader = function( imageLoaderLimit ) {
this.downloading = 0;
@ -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;
if ( !this.imageLoaderLimit || this.downloading < this.imageLoaderLimit ) {
this.downloading++;
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;
}
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);
}
}
});
this.downloading++;
job.start();
return true;
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,