imagesloaded.pkgd.min.js 5.5 KB

123456
  1. /*
  2. * imagesLoaded PACKAGED v4.1.4
  3. * JavaScript is all like "You images are done yet or what?"
  4. * MIT License
  5. */
  6. !function(a,b){"function"==typeof define&&define.amd?define("ev-emitter/ev-emitter",b):"object"==typeof module&&module.exports?module.exports=b():a.EvEmitter=b()}("undefined"!=typeof window?window:this,function(){function a(){}var b=a.prototype;return b.on=function(c,g){if(c&&g){var d=this._events=this._events||{},f=d[c]=d[c]||[];return f.indexOf(g)==-1&&f.push(g),this}},b.once=function(c,g){if(c&&g){this.on(c,g);var d=this._onceEvents=this._onceEvents||{},f=d[c]=d[c]||{};return f[g]=!0,this}},b.off=function(c,g){var d=this._events&&this._events[c];if(d&&d.length){var f=d.indexOf(g);return f!=-1&&d.splice(f,1),this}},b.emitEvent=function(c,k){var d=this._events&&this._events[c];if(d&&d.length){d=d.slice(0),k=k||[];for(var f=this._onceEvents&&this._onceEvents[c],g=0;g<d.length;g++){var h=d[g],j=f&&f[h];j&&(this.off(c,h),delete f[h]),h.apply(this,k)}return this}},b.allOff=function(){delete this._events,delete this._onceEvents},a}),function(a,b){"function"==typeof define&&define.amd?define(["ev-emitter/ev-emitter"],function(c){return b(a,c)}):"object"==typeof module&&module.exports?module.exports=b(a,require("ev-emitter")):a.imagesLoaded=b(a,a.EvEmitter)}("undefined"!=typeof window?window:this,function(f,q){function j(a,h){for(var d in h){a[d]=h[d]}return a}function k(a){if(Array.isArray(a)){return a}var d="object"==typeof a&&"number"==typeof a.length;return d?c.call(a):[a]}function l(a,i,d){if(!(this instanceof l)){return new l(a,i,d)}var h=a;return"string"==typeof a&&(h=document.querySelectorAll(a)),h?(this.elements=k(h),this.options=j({},this.options),"function"==typeof i?d=i:j(this.options,i),d&&this.on("always",d),this.getImages(),g&&(this.jqDeferred=new g.Deferred),void setTimeout(this.check.bind(this))):void b.error("Bad element for imagesLoaded "+(h||a))}function m(a){this.img=a}function p(a,d){this.url=a,this.element=d,this.img=new Image}var g=f.jQuery,b=f.console,c=Array.prototype.slice;l.prototype=Object.create(q.prototype),l.prototype.options={},l.prototype.getImages=function(){this.images=[],this.elements.forEach(this.addElementImages,this)},l.prototype.addElementImages=function(a){"IMG"==a.nodeName&&this.addImage(a),this.options.background===!0&&this.addElementBackgroundImages(a);var y=a.nodeType;if(y&&v[y]){for(var d=a.querySelectorAll("img"),h=0;h<d.length;h++){var u=d[h];this.addImage(u)}if("string"==typeof this.options.background){var w=a.querySelectorAll(this.options.background);for(h=0;h<w.length;h++){var x=w[h];this.addElementBackgroundImages(x)}}}};var v={1:!0,9:!0,11:!0};return l.prototype.addElementBackgroundImages=function(a){var s=getComputedStyle(a);if(s){for(var d=/url\((['"])?(.*?)\1\)/gi,h=d.exec(s.backgroundImage);null!==h;){var r=h&&h[2];r&&this.addBackground(r,a),h=d.exec(s.backgroundImage)}}},l.prototype.addImage=function(a){var d=new m(a);this.images.push(d)},l.prototype.addBackground=function(a,h){var d=new p(a,h);this.images.push(d)},l.prototype.check=function(){function a(h,o,r){setTimeout(function(){d.progress(h,o,r)})}var d=this;return this.progressedCount=0,this.hasAnyBroken=!1,this.images.length?void this.images.forEach(function(e){e.once("progress",a),e.check()}):void this.complete()},l.prototype.progress=function(a,h,d){this.progressedCount++,this.hasAnyBroken=this.hasAnyBroken||!a.isLoaded,this.emitEvent("progress",[this,a,h]),this.jqDeferred&&this.jqDeferred.notify&&this.jqDeferred.notify(this,a),this.progressedCount==this.images.length&&this.complete(),this.options.debug&&b&&b.log("progress: "+d,a,h)},l.prototype.complete=function(){var a=this.hasAnyBroken?"fail":"done";if(this.isComplete=!0,this.emitEvent(a,[this]),this.emitEvent("always",[this]),this.jqDeferred){var d=this.hasAnyBroken?"reject":"resolve";this.jqDeferred[d](this)}},m.prototype=Object.create(q.prototype),m.prototype.check=function(){var a=this.getIsImageComplete();return a?void this.confirm(0!==this.img.naturalWidth,"naturalWidth"):(this.proxyImage=new Image,this.proxyImage.addEventListener("load",this),this.proxyImage.addEventListener("error",this),this.img.addEventListener("load",this),this.img.addEventListener("error",this),void (this.proxyImage.src=this.img.src))},m.prototype.getIsImageComplete=function(){return this.img.complete&&this.img.naturalWidth},m.prototype.confirm=function(a,d){this.isLoaded=a,this.emitEvent("progress",[this,this.img,d])},m.prototype.handleEvent=function(a){var d="on"+a.type;this[d]&&this[d](a)},m.prototype.onload=function(){this.confirm(!0,"onload"),this.unbindEvents()},m.prototype.onerror=function(){this.confirm(!1,"onerror"),this.unbindEvents()},m.prototype.unbindEvents=function(){this.proxyImage.removeEventListener("load",this),this.proxyImage.removeEventListener("error",this),this.img.removeEventListener("load",this),this.img.removeEventListener("error",this)},p.prototype=Object.create(m.prototype),p.prototype.check=function(){this.img.addEventListener("load",this),this.img.addEventListener("error",this),this.img.src=this.url;var a=this.getIsImageComplete();a&&(this.confirm(0!==this.img.naturalWidth,"naturalWidth"),this.unbindEvents())},p.prototype.unbindEvents=function(){this.img.removeEventListener("load",this),this.img.removeEventListener("error",this)},p.prototype.confirm=function(a,d){this.isLoaded=a,this.emitEvent("progress",[this,this.element,d])},l.makeJQueryPlugin=function(a){a=a||f.jQuery,a&&(g=a,g.fn.imagesLoaded=function(d,n){var h=new l(this,d,n);return h.jqDeferred.promise(g(this))})},l.makeJQueryPlugin(),l});