-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathjquery.preload.min.js
More file actions
8 lines (8 loc) · 1.63 KB
/
jquery.preload.min.js
File metadata and controls
8 lines (8 loc) · 1.63 KB
1
2
3
4
5
6
7
8
/**
* jQuery.Preload - Multifunctional preloader
* Copyright (c) 2008-2016 Ariel Flesler - aflesler<a>gmail<d>com | http://flesler.blogspot.com
* Licensed under MIT
* @author Ariel Flesler
* @version 1.1.0
*/
;(function($){var j=$.preload=function(c,d){if(c.split)c=$(c);d=$.extend({},j.defaults,d);var f=$.map(c,function(a){if(!a)return;if(a.split)return d.base+a+d.ext;var b=d.srcAttribute?$(a).attr(d.srcAttribute):a.src||a.href;if(typeof d.placeholder=='string'&&a.src)a.src=d.placeholder;if(b&&d.find)b=b.replace(d.find,d.replace);return b||null});var g={loaded:0,failed:0,next:0,done:0,total:f.length};if(!g.total)return finish();var h=$(Array(d.threshold+1).join('<img/>')).on('load',handler).on('error',handler).bind('abort',handler).each(fetch);function handler(e){g.element=this;g.found=e.type=='load';g.image=this.src;g.index=this.index;var a=g.original=c[this.index];g[g.found?'loaded':'failed']++;g.done++;if(d.enforceCache)j.cache.push($('<img/>').attr('src',g.image)[0]);if(d.placeholder&&a.src)a.src=g.found?g.image:d.notFound||a.src;if(d.onComplete)d.onComplete(g);if(g.done<g.total)fetch(0,this);else{if(h&&h.unbind)h.unbind('load').unbind('error').unbind('abort');h=null;finish()}};function fetch(i,a,b){if(a.attachEvent&&g.next&&g.next%j.gap==0&&!b){setTimeout(function(){fetch(i,a,true)},0);return false}if(g.next==g.total)return false;a.index=g.next;a.src=f[g.next++];if(d.onRequest){g.index=a.index;g.element=a;g.image=a.src;g.original=c[g.next-1];d.onRequest(g)}};function finish(){if(d.onFinish)d.onFinish(g)}};j.gap=14;j.cache=[];j.defaults={threshold:2,base:'',ext:'',replace:''};$.fn.preload=function(a){j(this,a);return this}})(jQuery);