forked from aFarkas/lazysizes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ls.unload.min.js
2 lines (2 loc) · 2.32 KB
/
ls.unload.min.js
1
2
/*! lazysizes - v2.0.0 */
!function(a,b,c){"use strict";function d(){if(a.lazySizes&&!f){var c=b.documentElement,h=function(){var a,b=function(){j.checkElements(),a=!1};return function(){a||(a=!0,setTimeout(b,999))}}();e=lazySizes.cfg,removeEventListener("lazybeforeunveil",d),"unloadClass"in e||(e.unloadClass="lazyunload"),"unloadedClass"in e||(e.unloadedClass="lazyunloaded"),"unloadHidden"in e||(e.unloadHidden=!0),"emptySrc"in e||(e.emptySrc="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="),"autoUnload"in e||(e.autoUnload=!0),"unloadPixelThreshold"in e||(e.unloadPixelThreshold=6e4),e.autoUnload&&c.addEventListener("load",function(a){a.target.naturalWidth*a.target.naturalHeight>e.unloadPixelThreshold&&a.target.className&&a.target.className.indexOf&&-1!=a.target.className.indexOf(lazySizesConfig.loadingClass)&&-1==a.target.className.indexOf(lazySizesConfig.preloadClass)&&lazySizes.aC(a.target,lazySizesConfig.unloadClass)},!0),lazySizes.unloader=j,g=1.1*(e.expand*e.expFactor+99),f=b.getElementsByClassName([e.unloadClass,e.loadedClass].join(" ")),setInterval(h,9999),addEventListener("lazybeforeunveil",h),addEventListener("lazybeforeunveil",j._reload,!0)}}if(b.addEventListener){var e,f,g,h=[],i=a.requestAnimationFrame||setTimeout,j={checkElements:function(){var a,b,c,d=-1*g,k=d,l=innerHeight+g,m=innerWidth+g;for(a=0,b=f.length;b>a;a++)c=f[a].getBoundingClientRect(),(c.top>l||c.bottom<d||c.left>m||c.right<k||e.unloadHidden&&!c.top&&!c.bottom&&!c.left&&!c.right)&&h.push(f[a]);i(j.unloadElements)},unload:function(a){var b,c,d,f,g=a.parentNode;if(lazySizes.rC(a,e.loadedClass),a.getAttribute(e.srcsetAttr)&&(a.setAttribute("srcset",e.emptySrc),c=!0),g&&"PICTURE"==g.nodeName.toUpperCase()){for(b=g.getElementsByTagName("source"),d=0,f=b.length;f>d;d++)b[d].setAttribute("srcset",e.emptySrc);c=!0}lazySizes.hC(a,e.autosizesClass)&&(lazySizes.rC(a,e.autosizesClass),a.setAttribute(e.sizesAttr,"auto")),(c||a.getAttribute(e.srcAttr))&&(a.src=e.emptySrc),lazySizes.aC(a,e.unloadedClass),lazySizes.aC(a,e.lazyClass),lazySizes.fire(a,"lazyafterunload")},unloadElements:function(a){for(a=Array.isArray(a)?a:h;a.length;)j.unload(a.shift())},_reload:function(a){lazySizes.hC(a.target,e.unloadedClass)&&a.detail&&(a.detail.reloaded=!0,lazySizes.rC(a.target,e.unloadedClass))}};addEventListener("lazybeforeunveil",d)}}(window,document);