/*! * EventEmitter v4.2.6 - git.io/ee * Oliver Caldwell * MIT license * @preserve */ (function(){function e(){}function t(e,t){for(var n=e.length;n--;)if(e[n].listener===t)return n;return-1}function n(e){return function t(){return this[e].apply(this,arguments)}}var i=e.prototype,r=this,o=r.EventEmitter;i.getListeners=function s(e){var t=this._getEvents(),n,i;if("object"==typeof e){n={};for(i in t)t.hasOwnProperty(i)&&e.test(i)&&(n[i]=t[i])}else n=t[e]||(t[e]=[]);return n},i.flattenListeners=function f(e){var t=[],n;for(n=0;nn;n++)t.push(e[n]);else t.push(e);return t}function f(e,t,n){if(!(this instanceof f))return new f(e,t);"string"==typeof e&&(e=document.querySelectorAll(e)),this.elements=s(e),this.options=r({},this.options),"function"==typeof t?n=t:r(this.options,t),n&&this.on("always",n),this.getImages(),$&&(this.jqDeferred=new $.Deferred);var i=this;setTimeout(function(){i.check()})}function c(e){this.img=e}function a(e){this.src=e,v[e]=this}var $=t.jQuery,u=t.console,h="undefined"!=typeof u,d=Object.prototype.toString;f.prototype=new n,f.prototype.options={},f.prototype.getImages=function(){this.images=[];for(var e=0,t=this.elements.length;t>e;e++){var n=this.elements[e];"IMG"===n.nodeName&&this.addImage(n);var i=n.nodeType;if(i&&(1===i||9===i||11===i))for(var r=n.querySelectorAll("img"),o=0,s=r.length;s>o;o++){var f=r[o];this.addImage(f)}}},f.prototype.addImage=function(e){var t=new c(e);this.images.push(t)},f.prototype.check=function(){function e(e,r){return t.options.debug&&h&&u.log("confirm",e,r),t.progress(e),n++,n===i&&t.complete(),!0}var t=this,n=0,i=this.images.length;if(this.hasAnyBroken=!1,!i)return void this.complete();for(var r=0;i>r;r++){var o=this.images[r];o.on("confirm",e),o.check()}},f.prototype.progress=function(e){this.hasAnyBroken=this.hasAnyBroken||!e.isLoaded;var t=this;setTimeout(function(){t.emit("progress",t,e),t.jqDeferred&&t.jqDeferred.notify&&t.jqDeferred.notify(t,e)})},f.prototype.complete=function(){var e=this.hasAnyBroken?"fail":"done";this.isComplete=!0;var t=this;setTimeout(function(){if(t.emit(e,t),t.emit("always",t),t.jqDeferred){var n=t.hasAnyBroken?"reject":"resolve";t.jqDeferred[n](t)}})},$&&($.fn.imagesLoaded=function(e,t){var n=new f(this,e,t);return n.jqDeferred.promise($(this))}),c.prototype=new n,c.prototype.check=function(){var e=v[this.img.src]||new a(this.img.src);if(e.isConfirmed)return void this.confirm(e.isLoaded,"cached was confirmed");if(this.img.complete&&void 0!==this.img.naturalWidth)return void this.confirm(0!==this.img.naturalWidth,"naturalWidth");var t=this;e.on("confirm",function(e,n){return t.confirm(e.isLoaded,n),!0}),e.check()},c.prototype.confirm=function(e,t){this.isLoaded=e,this.emit("confirm",this,t)};var v={};return a.prototype=new n,a.prototype.check=function(){if(!this.isChecked){var e=new Image;i.bind(e,"load",this),i.bind(e,"error",this),e.src=this.src,this.isChecked=!0}},a.prototype.handleEvent=function(e){var t="on"+e.type;this[t]&&this[t](e)},a.prototype.onload=function(e){this.confirm(!0,"onload"),this.unbindProxyEvents(e)},a.prototype.onerror=function(e){this.confirm(!1,"onerror"),this.unbindProxyEvents(e)},a.prototype.confirm=function(e,t){this.isConfirmed=!0,this.isLoaded=e,this.emit("confirm",this,t)},a.prototype.unbindProxyEvents=function(e){i.unbind(e.target,"load",this),i.unbind(e.target,"error",this)},f});