-
Notifications
You must be signed in to change notification settings - Fork 0
/
imgloader.min.js
1 lines (1 loc) · 1.23 KB
/
imgloader.min.js
1
(function(e,t){"use strict";if(!Object.keys){Object.keys=function(e){var t=[],n;for(n in e){if(Object.prototype.hasOwnProperty.call(e,n)){t.push(n)}}return t}}if(!e.ImgLoader){e.ImgLoader={}}var n=ImgLoader.settings={loadImgTags:true,loadBackgroundImages:true,loadItems:null,loadContext:null,itemCompletedCallback:null,itemsCompletedCallback:null};ImgLoader.loadImages=function(e){t.extend(n,e);var r=0,i,s,o;var u=Object.keys(this.getImages());i=u.length;s=n.itemCompletedCallback||t.noop;o=n.itemsCompletedCallback||t.noop;if(i===0){o();return}for(var a=0;a<i;a++){t("<img/>").on("load.imgLoader error.imgLoader",function(e){r++;s(r/i,e.target.src,e.type==="load");if(r===i){o()}}).attr("src",u[a])}};ImgLoader.getImages=function(){var e={};if(n.loadImgTags){t('img[src!=""]',n.loadContext).each(function(){e[t(this).attr("src")]=""})}if(n.loadBackgroundImages){var r=/url\(\s*(['"]?)(.*?)\1\s*\)/g;t("*",n.loadContext).each(function(){var n=t(this).css("background-image"),i,s;if(n===""||n==="none"){return}while(i=r.exec(n)){s=i[2];if(s.slice(0,5)!=="data:"){e[s]=""}}})}if(n.loadItems){var i=n.loadItems;if(typeof i=="string"||i instanceof String){i=[i]}if(i instanceof Array){for(var s=0;s<i.length;s++){e[i[s]]=""}}}return e}})(window,jQuery,undefined)