| Apache Linux webd001.cluster107.gra.hosting.ovh.net 5.15.167-ovh-vps-grsec-zfs-classid #1 SMP Tue Sep 17 08:14:20 UTC 2024 x86_64 uid=2234(oyaide) gid=100(users) groups=100(users) server ip : 213.186.33.18 | your ip : 216.73.216.136 safemode OFF > / home / oyaide / www / moycompany.com / piwigo2 / themes / default / js / |
| Filename | /home/oyaide/www/moycompany.com/piwigo2/themes/default/js/image.loader.js |
| Size | 1.59 kb |
| Permission | rwxr-xr-x |
| Owner | oyaide : users |
| Create time | 26-May-2013 16:30 |
| Last modified | 08-Jan-2012 20:25 |
| Last accessed | 08-Jan-2012 20:25 |
| Actions | edit | rename | delete | download (gzip) |
| View | text | code | image |
function ImageLoader(opts) {
this.opts = jQuery.extend( {
maxRequests: 6,
onChanged: jQuery.noop
}, opts||{} );
}
ImageLoader.prototype = {
loaded: 0,
errors: 0,
errorEma: 0,
pause: false,
current: [],
queue: [],
pool: [],
remaining: function() {
return this.current.length + this.queue.length;
},
add: function(urls) {
this.queue = this.queue.concat( urls );
this._fireChanged("add");
this._checkQueue();
},
clear: function() {
this.queue.length = 0;
while (this.current.length)
jQuery( this.current.pop() ).unbind();
this.loaded = this.errors = this.errorEma = 0;
},
pause: function(val) {
if (val !== undefined)
{
this.paused = val;
this._checkQueue();
}
return this.paused;
},
_checkQueue: function() {
while (!this.paused
&& this.queue.length
&& this.current.length < this.opts.maxRequests)
{
this._processOne( this.queue.shift() );
}
},
_processOne: function(url) {
var img = this.pool.shift() || new Image;
this.current.push(img);
var that = this;
jQuery(img).bind( "load error abort", function(e) {
//img.onload = function(e) {
jQuery(img).unbind();
img.onload=null;
that.current.splice(jQuery.inArray(img, that.current), 1);
if (e.type==="load") {
that.loaded++;
that.errorEma *= 0.9;
}
else {
that.errors++;
that.errorEma++;
if (that.errorEma>=20 && that.errorEma<21)
that.paused = true;
}
that._fireChanged(e.type, img);
that._checkQueue();
that.pool.push(img);
} );
img.src = url;
},
_fireChanged: function(type, img) {
this.opts.onChanged(type, img);
}
}