removed ImageLoader abstraction (loadImage is noe method of Drawer) since its constructor was only called once and the resulting object was kept psuedo-private.

This commit is contained in:
thatcher 2011-12-27 18:17:24 -05:00
parent e591acfadb
commit 8ba072a1a9
4 changed files with 152 additions and 156 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/imageloader.js" />
<file name="src/tilesource.js" />
<file name="src/dzitilesource.js" />
<file name="src/button.js" />

View File

@ -2389,81 +2389,6 @@ $.Profiler.prototype = {
}( OpenSeadragon ));
(function( $ ){
//TODO: make TIMEOUT configurable
var TIMEOUT = 5000;
$.ImageLoader = function( imageLoaderLimit ) {
this.downloading = 0;
this.imageLoaderLimit = imageLoaderLimit;
};
$.ImageLoader.prototype = {
loadImage: function(src, callback) {
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;
}
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( $ ){
$.TileSource = function(width, height, tileSize, tileOverlap, minLevel, maxLevel) {
@ -3398,6 +3323,9 @@ $.Tile.prototype = {
var QUOTA = 100; // the max number of images we should keep in memory
var MIN_PIXEL_RATIO = 0.5; // the most shrunk a tile should be
//TODO: make TIMEOUT configurable
var TIMEOUT = 5000;
var browser = $.Utils.getBrowser();
var browserVer = $.Utils.getBrowserVersion();
@ -3419,7 +3347,9 @@ $.Drawer = function(source, viewport, elmt) {
this._source = source;
this.config = this._viewport.config;
this._imageLoader = new $.ImageLoader(this.config.imageLoaderLimit);
this.downloading = 0;
this.imageLoaderLimit = this.config.imageLoaderLimit;
this._profiler = new $.Profiler();
this._minLevel = source.minLevel;
@ -3515,8 +3445,15 @@ $.Drawer.prototype = {
},
_loadTile: function(tile, time) {
tile.loading = this._imageLoader.loadImage(tile.url,
$.Utils.createCallback(null, $.delegate(this, this._onTileLoad), tile, time));
tile.loading = this.loadImage(
tile.url,
$.Utils.createCallback(
null,
$.delegate(this, this._onTileLoad),
tile,
time
)
);
},
_onTileLoad: function(tile, time, image) {
@ -3966,7 +3903,68 @@ $.Drawer.prototype = {
},
idle: function() {
},
loadImage: function(src, callback) {
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(){
finishLoadingImage( image, complete, true );
};
image.onabort = image.onerror = function(){
finishLoadingImage( image, complete, false );
};
jobid = window.setTimeout( function(){
finishLoadingImage( image, complete, false, jobid );
}, TIMEOUT );
loading = true;
image.src = src;
}
return loading;
}
};
function finishLoadingImage( 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

@ -4,6 +4,9 @@
var QUOTA = 100; // the max number of images we should keep in memory
var MIN_PIXEL_RATIO = 0.5; // the most shrunk a tile should be
//TODO: make TIMEOUT configurable
var TIMEOUT = 5000;
var browser = $.Utils.getBrowser();
var browserVer = $.Utils.getBrowserVersion();
@ -25,7 +28,9 @@ $.Drawer = function(source, viewport, elmt) {
this._source = source;
this.config = this._viewport.config;
this._imageLoader = new $.ImageLoader(this.config.imageLoaderLimit);
this.downloading = 0;
this.imageLoaderLimit = this.config.imageLoaderLimit;
this._profiler = new $.Profiler();
this._minLevel = source.minLevel;
@ -121,8 +126,15 @@ $.Drawer.prototype = {
},
_loadTile: function(tile, time) {
tile.loading = this._imageLoader.loadImage(tile.url,
$.Utils.createCallback(null, $.delegate(this, this._onTileLoad), tile, time));
tile.loading = this.loadImage(
tile.url,
$.Utils.createCallback(
null,
$.delegate(this, this._onTileLoad),
tile,
time
)
);
},
_onTileLoad: function(tile, time, image) {
@ -572,7 +584,68 @@ $.Drawer.prototype = {
},
idle: function() {
},
loadImage: function(src, callback) {
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(){
finishLoadingImage( image, complete, true );
};
image.onabort = image.onerror = function(){
finishLoadingImage( image, complete, false );
};
jobid = window.setTimeout( function(){
finishLoadingImage( image, complete, false, jobid );
}, TIMEOUT );
loading = true;
image.src = src;
}
return loading;
}
};
function finishLoadingImage( 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,75 +1 @@
(function( $ ){
//TODO: make TIMEOUT configurable
var TIMEOUT = 5000;
$.ImageLoader = function( imageLoaderLimit ) {
this.downloading = 0;
this.imageLoaderLimit = imageLoaderLimit;
};
$.ImageLoader.prototype = {
loadImage: function(src, callback) {
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;
}
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 ));