filesbox/web/dist/design/designstatic/front/js/imagesloaded.pkgd.min.js

2 lines
4.3 KiB
JavaScript
Raw Normal View History

2024-07-26 06:10:54 +00:00
(function(h,a){"use strict";typeof define=="function"&&define.amd?define(["ev-emitter/ev-emitter"],function(m){return a(h,m)}):typeof module=="object"&&module.exports?module.exports=a(h,require("ev-emitter")):h.imagesLoaded=a(h,h.EvEmitter)})(typeof window!="undefined"?window:this,function(h,a){"use strict";function m(t,e){for(var i in e)t[i]=e[i];return t}function n(t,e,i){if(!(this instanceof n))return new n(t,e,i);var o=t;typeof t=="string"&&(o=document.querySelectorAll(t)),o?(this.elements=function(r){return Array.isArray(r)?r:typeof r=="object"&&typeof r.length=="number"?g.call(r):[r]}(o),this.options=m({},this.options),typeof e=="function"?i=e:m(this.options,e),i&&this.on("always",i),this.getImages(),p&&(this.jqDeferred=new p.Deferred),setTimeout(this.check.bind(this))):u.error("Bad element for imagesLoaded "+(o||t))}function s(t){this.img=t}function d(t,e){this.url=t,this.element=e,this.img=new Image}var p=h.jQuery,u=h.console,g=Array.prototype.slice;(n.prototype=Object.create(a.prototype)).options={},n.prototype.getImages=function(){this.images=[],this.elements.forEach(this.addElementImages,this)},n.prototype.addElementImages=function(t){t.nodeName=="IMG"&&this.addImage(t),this.options.background===!0&&this.addElementBackgroundImages(t);var e=t.nodeType;if(e&&f[e]){for(var i=t.querySelectorAll("img"),o=0;o<i.length;o++){var r=i[o];this.addImage(r)}if(typeof this.options.background=="string"){var c=t.querySelectorAll(this.options.background);for(o=0;o<c.length;o++){var l=c[o];this.addElementBackgroundImages(l)}}}};var f={1:!0,9:!0,11:!0};return n.prototype.addElementBackgroundImages=function(t){var e=getComputedStyle(t);if(e)for(var i=/url\((['"])?(.*?)\1\)/gi,o=i.exec(e.backgroundImage);o!==null;){var r=o&&o[2];r&&this.addBackground(r,t),o=i.exec(e.backgroundImage)}},n.prototype.addImage=function(t){var e=new s(t);this.images.push(e)},n.prototype.addBackground=function(t,e){var i=new d(t,e);this.images.push(i)},n.prototype.check=function(){function t(i,o,r){setTimeout(function(){e.progress(i,o,r)})}var e=this;this.progressedCount=0,this.hasAnyBroken=!1,this.images.length?this.images.forEach(function(i){i.once("progress",t),i.check()}):this.complete()},n.prototype.progress=function(t,e,i){this.progressedCount++,this.hasAnyBroken=this.hasAnyBroken||!t.isLoaded,this.emitEvent("progress",[this,t,e]),this.jqDeferred&&this.jqDeferred.notify&&this.jqDeferred.notify(this,t),this.progressedCount==this.images.length&&this.complete(),this.options.debug&&u&&u.log("progress: "+i,t,e)},n.prototype.complete=function(){var t=this.hasAnyBroken?"fail":"done";if(this.isComplete=!0,this.emitEvent(t,[this]),this.emitEvent("always",[this]),this.jqDeferred){var e=this.hasAnyBroken?"reject":"resolve";this.jqDeferred[e](this)}},s.prototype=Object.create(a.prototype),s.prototype.check=function(){this.getIsImageComplete()?this.confirm(this.img.naturalWidth!==0,"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),this.proxyImage.src=this.img.src)},s.prototype.getIsImageComplete=function(){return this.img.complete&&this.img.naturalWidth},s.prototype.confirm=function(t,e){this.isLoaded=t,this.emitEvent("progress",[this,this.img,e])},s.prototype.handleEvent=function(t){var e="on"+t.type;this[e]&&this[e](t)},s.prototype.onload=function(){this.confirm(!0,"onload"),this.unbindEvents()},s.prototype.onerror=function(){this.confirm(!1,"onerror"),this.unbindEvents()},s.prototype.unbindEvents=function(){this.proxyImage.removeEventListener("load",this),this.proxyImage.removeEventListener("error",this),this.img.removeEventListener("load",this),this.img.removeEventListener("error",this)},d.prototype=Object.create(s.prototype),d.prototype.check=function(){this.img.addEventListener("load",this),this.img.addEventListener("error",this),this.img.src=this.url,this.getIsImageComplete()&&(this.confirm(this.img.naturalWidth!==0,"naturalWidth"),this.unbindEvents())},d.prototype.unbindEvents=function(){th