removed psuedo-privacy anti-patterns from imageloader.js in favor of simple pinning and public properties.

This commit is contained in:
thatcher 2011-12-13 18:51:35 -05:00
parent c7706ba66c
commit de14271399
2 changed files with 34 additions and 34 deletions

View File

@ -2472,14 +2472,21 @@ $.Job.prototype = {
(function( $ ){ (function( $ ){
$.ImageLoader = function(imageLoaderLimit) { $.ImageLoader = function( imageLoaderLimit ) {
this._downloading = 0; this.downloading = 0;
this.imageLoaderLimit = imageLoaderLimit; this.imageLoaderLimit = imageLoaderLimit;
}; };
$.ImageLoader.prototype = { $.ImageLoader.prototype = {
_onComplete: function(callback, src, image) { loadImage: function(src, callback) {
this._downloading--; var _this = this;
if (this.downloading >= this.imageLoaderLimit) {
return false;
}
var job = new $.Job(src, function(src, image){
_this.downloading--;
if (typeof (callback) == "function") { if (typeof (callback) == "function") {
try { try {
callback(image); callback(image);
@ -2488,16 +2495,9 @@ $.ImageLoader.prototype = {
" callback: " + e.message, e); " callback: " + e.message, e);
} }
} }
}, });
loadImage: function(src, callback) {
if (this._downloading >= this.imageLoaderLimit) {
return false;
}
var func = $.Utils.createCallback(null, $.delegate(this, this._onComplete), callback); this.downloading++;
var job = new $.Job(src, func);
this._downloading++;
job.start(); job.start();
return true; return true;

View File

@ -1,14 +1,21 @@
(function( $ ){ (function( $ ){
$.ImageLoader = function(imageLoaderLimit) { $.ImageLoader = function( imageLoaderLimit ) {
this._downloading = 0; this.downloading = 0;
this.imageLoaderLimit = imageLoaderLimit; this.imageLoaderLimit = imageLoaderLimit;
}; };
$.ImageLoader.prototype = { $.ImageLoader.prototype = {
_onComplete: function(callback, src, image) { loadImage: function(src, callback) {
this._downloading--; var _this = this;
if (this.downloading >= this.imageLoaderLimit) {
return false;
}
var job = new $.Job(src, function(src, image){
_this.downloading--;
if (typeof (callback) == "function") { if (typeof (callback) == "function") {
try { try {
callback(image); callback(image);
@ -17,16 +24,9 @@ $.ImageLoader.prototype = {
" callback: " + e.message, e); " callback: " + e.message, e);
} }
} }
}, });
loadImage: function(src, callback) {
if (this._downloading >= this.imageLoaderLimit) {
return false;
}
var func = $.Utils.createCallback(null, $.delegate(this, this._onComplete), callback); this.downloading++;
var job = new $.Job(src, func);
this._downloading++;
job.start(); job.start();
return true; return true;