mirror of
https://github.com/StarGazer114/stargazer114.github.io.git
synced 2025-01-09 06:48:17 +08:00
2 lines
7.1 KiB
JavaScript
2 lines
7.1 KiB
JavaScript
|
var LazyLoad=function(){"use strict";const e="undefined"!=typeof window,t=e&&!("onscroll"in window)||"undefined"!=typeof navigator&&/(gle|ing|ro)bot|crawl|spider/i.test(navigator.userAgent),a=e&&window.devicePixelRatio>1,s={elements_selector:".lazy",container:t||e?document:null,threshold:300,thresholds:null,data_src:"src",data_srcset:"srcset",data_sizes:"sizes",data_bg:"bg",data_bg_hidpi:"bg-hidpi",data_bg_multi:"bg-multi",data_bg_multi_hidpi:"bg-multi-hidpi",data_bg_set:"bg-set",data_poster:"poster",class_applied:"applied",class_loading:"loading",class_loaded:"loaded",class_error:"error",class_entered:"entered",class_exited:"exited",unobserve_completed:!0,unobserve_entered:!1,cancel_on_exit:!0,callback_enter:null,callback_exit:null,callback_applied:null,callback_loading:null,callback_loaded:null,callback_error:null,callback_finish:null,callback_cancel:null,use_native:!1,restore_on_error:!1},n=e=>Object.assign({},s,e),l=function(e,t){let a;const s="LazyLoad::Initialized",n=new e(t);try{a=new CustomEvent(s,{detail:{instance:n}})}catch(e){a=document.createEvent("CustomEvent"),a.initCustomEvent(s,!1,!1,{instance:n})}window.dispatchEvent(a)},o="src",r="srcset",i="sizes",c="poster",d="llOriginalAttrs",_="data",u="loading",g="loaded",b="applied",h="error",m="native",p="data-",v="ll-status",f=(e,t)=>e.getAttribute(p+t),E=e=>f(e,v),I=(e,t)=>((e,t,a)=>{const s=p+t;null!==a?e.setAttribute(s,a):e.removeAttribute(s)})(e,v,t),k=e=>I(e,null),A=e=>null===E(e),L=e=>E(e)===m,y=[u,g,b,h],w=(e,t,a,s)=>{e&&"function"==typeof e&&(void 0===s?void 0===a?e(t):e(t,a):e(t,a,s))},C=(t,a)=>{e&&""!==a&&t.classList.add(a)},O=(t,a)=>{e&&""!==a&&t.classList.remove(a)},x=e=>e.llTempImage,M=(e,t)=>{if(!t)return;const a=t._observer;a&&a.unobserve(e)},z=(e,t)=>{e&&(e.loadingCount+=t)},N=(e,t)=>{e&&(e.toLoadCount=t)},R=e=>{let t=[];for(let a,s=0;a=e.children[s];s+=1)"SOURCE"===a.tagName&&t.push(a);return t},T=(e,t)=>{const a=e.parentNode;a&&"PICTURE"===a.tagName&&R(a).forEach(t)},G=(e,t)=>{R(e).forEach(t)},D=[o],H=[o,c],V=[o,r,i],F=[_],B=e=>!!e[d],J=e=>e[d],S=e=>delete e[d],j=(e,t)=>{if(B(e))return;const a={};t.forEach((t=>{a[t]=e.getAttribute(t)})),e[d]=a},P=(e,t)=>{if(!B(e))return;const a=J(e);t.forEach((t=>{((e,t,a)=>{a?e.setAttribute(t,a):e.removeAttribute(t)})(e,t,a[t])}))},U=(e,t,a)=>{C(e,t.class_applied),I(e,b),a&&(t.unobserve_completed&&M(e,t),w(t.callback_applied,e,a))},$=(e,t,a)=>{C(e,t.class_loading),I(e,u),a&&(z(a,1),w(t.callback_loading,e,a))},q=(e,t,a)=>{a&&e.setAttribute(t,a)},K=(e,t)=>{q(e,i,f(e,t.data_sizes)),q(e,r,f(e,t.data_srcset)),q(e,o,f(e,t.data_src))},Q={IMG:(e,t)=>{T(e,(e=>{j(e,V),K(e,t)})),j(e,V),K(e,t)},IFRAME:(e,t)=>{j(e,D),q(e,o,f(e,t.data_src))},VIDEO:(e,t)=>{G(e,(e=>{j(e,D),q(e,o,f(e,t.data_src))})),j(e,H),q(e,c,f(e,t.data_poster)),q(e,o,f(e,t.data_src)),e.load()},OBJECT:(e,t)=>{j(e,F),q(e,_,f(e,t.data_src))}},W=["IMG","IFRAME","VIDEO","OBJECT"],X=(e,t)=>{!t||(e=>e.loadingCount>0)(t)||(e=>e.toLoadCount>0)(t)||w(e.callback_finish,t)},Y=(e,t,a)=>{e.addEventListener(t,a),e.llEvLisnrs[t]=a},Z=(e,t,a)=>{e.removeEventListener(t,a)},ee=e=>!!e.llEvLisnrs,te=e=>{if(!ee(e))return;const t=e.llEvLisnrs;for(let a in t){const s=t[a];Z(e,a,s)}delete e.llEvLisnrs},ae=(e,t,a)=>{(e=>{delete e.llTempImage})(e),z(a,-1),(e=>{e&&(e.toLoadCount-=1)})(a),O(e,t.class_loading),t.unobserve_completed&&M(e,a)},se=(e,t,a)=>{const s=x(e)||e;ee(s)||((e,t,a)=>{ee(e)||(e.llEvLisnrs={});const s="VIDEO"===e.tagName?"loadeddata":"load";Y(e,s,t),Y(e,"error",a)})(s,(n=>{((e,t,a,s)=>{const n=L(t);ae(t,a,s),C(t,a.class_loaded),I(t,g),w(a.callback_loaded,t,s),n||X(a,s)})(0,e,t,a),te(s)}),(n=>{((e,t,a,s)=>{const n=L(t);ae(t,a,s),C(t,a.class_error),I(t,h),w(a.callback_error,t,s),a.restore_on_error&&P(t,V),n||X(a,s)})(0,e,t,a),te(s)}))},ne=(e,t,s)=>{(e=>W.indexOf(e.tagName)>-1)(e)?((e,t,a)=>{se(e,t,a),((e,t,a)=>{const s=Q[e.tagName];s&&(s(e,t),$(e,t,a))})(e,t,a)})(e,t,s):((e,t,s)=>{(e=>{e.llTempImage=document.createElement("IMG")})(e),se(e,t,s),(e=>{B(e)||(e[d]={backgroundImage:e.style.backgroundImage})})(e),((e,t,s)=>{const n=f(e,t.data_bg),l=f(e,t.data_bg_hidpi),r=a&&
|