diff --git a/build.xml b/build.xml
index 41af2cac..34f3182b 100644
--- a/build.xml
+++ b/build.xml
@@ -28,7 +28,6 @@
-
diff --git a/openseadragon.js b/openseadragon.js
index 26a88fd3..50ce6167 100644
--- a/openseadragon.js
+++ b/openseadragon.js
@@ -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( $ ){
diff --git a/src/imageloader.js b/src/imageloader.js
index a1f1260c..2cfae0cd 100644
--- a/src/imageloader.js
+++ b/src/imageloader.js
@@ -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 ));
diff --git a/src/job.js b/src/job.js
deleted file mode 100644
index 03b8527e..00000000
--- a/src/job.js
+++ /dev/null
@@ -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 ));
diff --git a/src/viewer.js b/src/viewer.js
index c844a984..6cc82a86 100644
--- a/src/viewer.js
+++ b/src/viewer.js
@@ -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,