forked from aFarkas/lazysizes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlazysizes.min.js
3 lines (3 loc) · 5.54 KB
/
lazysizes.min.js
1
2
3
/*! lazysizes - v0.9.0 - 2015-02-06
Licensed MIT */
!function(a,b){a.lazySizes=b(a,a.document),"function"==typeof define&&define.amd&&define(a.lazySizes)}(window,function(a,b){"use strict";if(b.getElementsByClassName){var c,d=b.documentElement,e=/^picture$/i,f=["load","error","lazyincluded","_lazyloaded"],g=function(a,b){var c=new RegExp("(\\s|^)"+b+"(\\s|$)");return a.className.match(c)&&c},h=function(a,b){g(a,b)||(a.className+=" "+b)},i=function(a,b){var c;(c=g(a,b))&&(a.className=a.className.replace(c," "))},j=function(a,b,c){var d=c?"addEventListener":"removeEventListener";c&&j(a,b),f.forEach(function(c){a[d](c,b)})},k=function(a,c,d){var e=b.createEvent("Event");return e.initEvent(c,!0,!0),e.details=d||{},a.dispatchEvent(e),e},l=function(b,c){var d;a.HTMLPictureElement||((d=a.picturefill||a.respimage)?d({reevaluate:!0,reparse:!0,elements:[b]}):c&&c.src&&(b.src=c.src))},m=function(a,b){return getComputedStyle(a,null)[b]},n=function(a,d){for(var e=a.offsetWidth;e<c.minSize&&d&&d!=b.body&&!a._lazysizesWidth;)e=d.offsetWidth,d=d.parentNode;return e},o=function(a){var c,d,e=function(){c&&(c=!1,a())},f=function(){clearInterval(d),b.hidden||(e(),d=setInterval(e,66))};return b.addEventListener("visibilitychange",f),f(),function(a){c=!0,a===!0&&e()}},p=function(){var f,n,p,r,s,t,u,v,w,x,y,z,A=a.HTMLPictureElement&&navigator.userAgent.match(/hrome\/(\d+)/)&&40==RegExp.$1,B=/^img$/i,C=/^iframe$/i,D=-2,E=D,F=D,G=D,H=!0,I=0,J=0,K=0,L=function(a){J--,a&&a.target&&j(a.target,L),(!a||0>J||!a.target)&&(J=0)},M=function(a,b){var c,e=a,f="hidden"!=m(a,"visibility");for(w-=b,z+=b,x-=b,y+=b;f&&(e=e.offsetParent)&&e!=d;)f=r&&4>J||(m(e,"opacity")||1)>0,f&&"visible"!=m(e,"overflow")&&(c=e.getBoundingClientRect(),f=y>c.left-1&&x<c.right+1&&z>c.top-1&&w<c.bottom+1);return f},N=function(){var a,b,d,e,g,h,i,j=f.length,k=Date.now(),l=K;if(H||S(),j){for(;j>l&&f[l];l++,K++)if((h=f[l].getAttribute("data-expand"))&&(e=1*h)||(e=G),!(J>6&&(!h||"src"in f[l])))if(J>3&&e>D&&(e=D),i!==e&&(u=innerWidth+e,v=innerHeight+e,g=-1*e,i=e),a=f[l].getBoundingClientRect(),(z=a.bottom)>=g&&(w=a.top)<=v&&(y=a.right)>=g&&(x=a.left)<=u&&(z||y||x||w)&&(r&&G==E&&3>J&&4>I&&!h||M(f[l],e)))K--,k+=2,R(f[l]),d=!0;else{if(!t&&Date.now()-k>3)return K++,t=!0,void O();!d&&r&&!b&&3>J&&4>I&&(n[0]||c.preloadAfterLoad)&&(n[0]||!h&&(z||y||x||w||"auto"!=f[l].getAttribute(c.sizesAttr)))&&(b=n[0]||f[l])}K=0,t=!1,I++,F>G&&2>J&&I>4?(G=F,I=0,O()):G!=E&&(G=E),b&&!d&&R(b)}},O=o(N),P=function(a){h(a.target,c.loadedClass),i(a.target,c.loadingClass),j(a.target,P)},Q=function(a,b){try{a.contentWindow.location.replace(b)}catch(c){a.setAttribute("src",b)}},R=function(a,b){var d,f,m,n,o,p,t,u,v,w,x,y=a.currentSrc||a.src,z=B.test(a.nodeName),D=a.getAttribute(c.sizesAttr)||a.getAttribute("sizes"),E="auto"==D;if(!E&&r||!z||!y||a.complete||g(a,c.errorClass)){if(!(v=k(a,"lazybeforeunveil",{force:!!b})).defaultPrevented){if(D&&(E?q.updateElem(a,!0):a.setAttribute("sizes",D)),p=a.getAttribute(c.srcsetAttr),o=a.getAttribute(c.srcAttr),z&&(t=a.parentNode,u=e.test(t.nodeName||"")),w=v.details.firesLoad||"src"in a&&(p||o||u),w&&(J++,j(a,L,!0),clearTimeout(s),s=setTimeout(L,3e3)),u)for(d=t.getElementsByTagName("source"),f=0,m=d.length;m>f;f++)(x=c.customMedia[d[f].getAttribute("media")])&&d[f].setAttribute("media",x),n=d[f].getAttribute(c.srcsetAttr),n&&d[f].setAttribute("srcset",n);p?(a.setAttribute("srcset",p),A&&D&&a.removeAttribute("src")):o&&(C.test(a.nodeName)?Q(a,o):a.setAttribute("src",o)),c.addClasses&&(h(a,c.loadingClass),j(a,P,!0))}setTimeout(function(){"auto"==D&&h(a,c.autosizesClass),(p||u)&&l(a,{srcset:p,src:o}),i(a,c.lazyClass),(!w||a.complete&&y==(a.currentSrc||a.src))&&(w&&L(v),c.addClasses&&P(v)),a=null})}},S=function(){p&&!H&&(E=Math.max(Math.min(c.expand||c.threshold||120,300),9),F=4*E),H=!0},T=function(){p=!0,H=!1},U=function(){r=!0,T(),O(!0)},V=function(){f=b.getElementsByClassName(c.lazyClass),n=b.getElementsByClassName(c.lazyClass+" "+c.preloadClass),c.scroll&&addEventListener("scroll",O,!0),addEventListener("resize",function(){H=!1,O()}),a.MutationObserver?new MutationObserver(O).observe(d,{childList:!0,subtree:!0,attributes:!0}):(d.addEventListener("DOMNodeInserted",O,!0),d.addEventListener("DOMAttrModified",O,!0)),addEventListener("hashchange",O,!0),["transitionstart","transitionend","load","focus","mouseover","animationend","click"].forEach(function(a){b.addEventListener(a,O,!0)}),(r=/d$|^c/.test(b.readyState))||(addEventListener("load",U),b.addEventListener("DOMContentLoaded",O)),setTimeout(T,666),O(!0),O()};return{_i:V,checkElems:O,unveil:R}}(),q=function(){var a,d=function(a,b){var c,d,f,g,h,i=a.parentNode;if(i&&(c=n(a,i),h=k(a,"lazybeforesizes",{width:c,dataAttr:!!b}),!h.defaultPrevented&&(c=h.details.width,c&&c!==a._lazysizesWidth))){if(a._lazysizesWidth=c,c+="px",a.setAttribute("sizes",c),e.test(i.nodeName||""))for(d=i.getElementsByTagName("source"),f=0,g=d.length;g>f;f++)d[f].setAttribute("sizes",c);h.details.dataAttr||l(a,h.details)}},f=function(){var b,c=a.length;if(c)for(b=0;c>b;b++)d(a[b])},g=o(f),h=function(){a=b.getElementsByClassName(c.autosizesClass),addEventListener("resize",g)};return{_i:h,checkElems:g,updateElem:d}}(),r=function(){r.i||(r.i=!0,q._i(),p._i())};return function(){var b,d={lazyClass:"lazyload",loadedClass:"lazyloaded",loadingClass:"lazyloading",preloadClass:"lazypreload",scroll:!0,autosizesClass:"lazyautosizes",srcAttr:"data-src",srcsetAttr:"data-srcset",sizesAttr:"data-sizes",addClasses:!0,minSize:50,customMedia:{},init:!0};c=a.lazySizesConfig||{};for(b in d)b in c||(c[b]=d[b]);a.lazySizesConfig=c,c.init&&setTimeout(r)}(),{cfg:c,autoSizer:q,loader:p,init:r,uP:l,aC:h,rC:i,hC:g,fire:k,gW:n}}});