/** * lc-lazyload.js - (ES6 JS) Image preloader * Version: v3.0.0 - 2023-08-29 * Author: Luca Montanari (LCweb) * Website: https://lcweb.it * Licensed under the MIT license */ !function(){"use strict";if("function"==typeof window.lc_lazyload)return!0;window.lc_lzl_cache={};const t={direct_array:!1,target_attr:"src",target_srcset:"srcset",oneLoaded:null,allLoaded:null};window.lc_lazyload=function(e,r){if("object"!=typeof r)return console.error("LC lazyload","Options must be an object");const c=(r=Object.assign({},t,r)).direct_array?e:function(t){let e=[];return t.forEach((function(t,r){t instanceof Element&&e.push(t)})),e}("string"!=typeof(l=e)?l instanceof Element?[l]:Object.values(l):((l.match(/(#[0-9][^\s:,]*)/g)||[]).forEach((function(t){l=l.replace(t,'[id="'+t.replace("#","")+'"]')})),document.querySelectorAll(l)));var l;let a=[],o=0;const n=function(t,e,c,l=0){setTimeout((function(){const a=t.currentSrc;if(!a)return l<500?n(t,e,c,l+1):(console.error("LC lazyload - empty img url - "+c,"| targeted attribute: "+r.target_srcset+" |",e),!1);i(a,e)}),10)},s=function(){o==c.length&&"function"==typeof r.allLoaded&&r.allLoaded.call(null,a)},i=function(t,e=!1){if(void 0!==lc_lzl_cache[t])a[t]={w:lc_lzl_cache[t].w,h:lc_lzl_cache[t].h},o++,u(t,lc_lzl_cache[t].w,lc_lzl_cache[t].h,e),s();else{let r=new Image;r.src=t,r.onload=r=>{a[t]={w:r.target.width,h:r.target.height},lc_lzl_cache[t]=a[t],o++,u(t,r.target.width,r.target.height,e),s()}}},u=function(t,e,c,l){l&&l.hasOwnProperty("lclzl_srcset")&&"srcset"!=r.target_srcset&&(l.setAttribute("srcset",l.getAttribute(r.target_srcset)),l.removeAttribute(r.target_srcset)),"function"==typeof r.oneLoaded&&r.oneLoaded.call(null,t,e,c,l)};r.direct_array?c.some(((t,e)=>{t?i(t):console.log("LC lazyload - empty img url - "+(e+1))})):c.forEach((function(t,e){const c=e+1;if(null!==t.getAttribute(r.target_srcset))if("srcset"==r.target_srcset)n(t,t,c);else{t.lclzl_srcset=!0;let e=document.createElement("IMG");e.srcset=t.getAttribute(r.target_srcset),n(e,t,c)}else{const e=!!t.getAttribute(r.target_attr)&&t.getAttribute(r.target_attr);e||console.log("LC lazyload - empty img url - "+c,"| targeted attribute: "+r.target_attr+" |",t),i(e,t)}}))}}();