lazysizes
Version:
High performance (jankfree) lazy loader for images (including responsive images), iframes and scripts (widgets).
3 lines (2 loc) • 2.51 kB
JavaScript
/*! lazysizes - v5.3.2 */
!function(e,t){var a=function(){t(e.lazySizes),e.removeEventListener("lazyunveilread",a,!0)};t=t.bind(null,e,e.document),"object"==typeof module&&module.exports?t(require("lazysizes")):"function"==typeof define&&define.amd?define(["lazysizes"],t):e.lazySizes?a():e.addEventListener("lazyunveilread",a,!0)}(window,function(s,d,i){"use strict";var r,u,o,c,f,A;d.addEventListener&&(o=i.cfg,c=[],f=s.requestAnimationFrame||setTimeout,A={checkElements:function(){for(var e,t=1.1*(i._defEx+99),a=-1*t,n=a,l=innerHeight+t,s=innerWidth+t,d=0,o=u.length;d<o;d++)((e=u[d].getBoundingClientRect()).top>l||e.bottom<a||e.left>s||e.right<n||r.unloadHidden&&!e.top&&!e.bottom&&!e.left&&!e.right)&&c.push(u[d]);f(A.unloadElements)},unload:function(e){var t,a,n,l,s=e.parentNode;if(i.rC(e,r.loadedClass),e.getAttribute(r.srcsetAttr)&&(e.setAttribute("srcset",r.emptySrc),a=!0),s&&"PICTURE"==s.nodeName.toUpperCase()){for(n=0,l=(t=s.getElementsByTagName("source")).length;n<l;n++)t[n].setAttribute("srcset",r.emptySrc);a=!0}i.hC(e,r.autosizesClass)&&(i.rC(e,r.autosizesClass),e.setAttribute(r.sizesAttr,"auto")),(a||e.getAttribute(r.srcAttr))&&(e.src=r.emptySrc),i.aC(e,r.unloadedClass),i.aC(e,r.lazyClass),i.fire(e,"lazyafterunload")},unloadElements:function(e){for(e=Array.isArray(e)?e:c;e.length;)A.unload(e.shift())},_reload:function(e){i.hC(e.target,r.unloadedClass)&&e.detail&&(e.detail.reloaded=!0,i.rC(e.target,r.unloadedClass))}},addEventListener("lazybeforeunveil",function e(){var t,a,n;function l(){A.checkElements(),n=!1}s.lazySizes&&!u&&(t=d.documentElement,a=function(){n||(n=!0,setTimeout(l,999))},r=i.cfg,removeEventListener("lazybeforeunveil",e),"unloadClass"in r||(r.unloadClass="lazyunload"),"unloadedClass"in r||(r.unloadedClass="lazyunloaded"),"unloadHidden"in r||(r.unloadHidden=!0),"emptySrc"in r||(r.emptySrc="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="),"autoUnload"in r||(r.autoUnload=!0),"unloadPixelThreshold"in r||(r.unloadPixelThreshold=6e4),r.autoUnload&&t.addEventListener("load",function(e){e.target.naturalWidth*e.target.naturalHeight>r.unloadPixelThreshold&&e.target.className&&e.target.className.indexOf&&-1!=e.target.className.indexOf(o.loadingClass)&&-1==e.target.className.indexOf(o.preloadClass)&&i.aC(e.target,o.unloadClass)},!0),i.unloader=A,u=d.getElementsByClassName([r.unloadClass,r.loadedClass].join(" ")),setInterval(a,9999),addEventListener("lazybeforeunveil",a),addEventListener("lazybeforeunveil",A._reload,!0))}))});