forked from aFarkas/lazysizes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ls.optimumx.min.js
3 lines (2 loc) · 2.67 KB
/
ls.optimumx.min.js
1
2
3
/*! lazysizes - v5.3.2 */
!function(e,t){var n;e&&(n=function(){t(e.lazySizes),e.removeEventListener("lazyunveilread",n,!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?n():e.addEventListener("lazyunveilread",n,!0))}("undefined"!=typeof window?window:0,function(t,e,s){"use strict";var c,d,n,r,o,i,l,u,f,m,a;function p(e,t,n,i,r,a,d,u){o.push({c:t,u:n,w:+("w"==u?d:i)})}function v(e,t){return e.w-t.w}function y(e,t){var n={srcset:e.getAttribute(s.cfg.srcsetAttr)||""},i=r(n.srcset);return Object.defineProperty(e,t,{value:n,writable:!0}),n.cands=i,n.index=0,n.dirty=!1,i[0]&&i[0].w?(i.sort(v),n.cSrcset=[i[n.index].c]):(n.cSrcset=n.srcset?[n.srcset]:[],n.cands=[]),n}function g(e,t,n,i,r){var a,d=e[r];d&&(a=d.index,u[r](d,t,n),d.dirty&&a==d.index||(d.cSrcset.join(", "),e.setAttribute(i,d.cSrcset.join(", ")),d.dirty=!0))}t.addEventListener&&(d=/^picture$/i,n=e.documentElement,i=/(([^,\s].[^\s]+)\s+(\d+)(w|h)(\s+(\d+)(w|h))?)/g,r=function(e){return o=[],e.replace(i,p),o},l=function(e,t){var n,i,r,a;if(!e[t]&&(a=e.parentNode||{},e[t]=y(e,t),e[t].isImg=!0,d.test(a.nodeName||"")))for(e[t].picture=!0,i=0,r=(n=a.getElementsByTagName("source")).length;i<r;i++)y(n[i],t).isImg=!1;return e[t]},u={_lazyOptimumx:function(e,t,n){for(var i,r,a,d,u,s,c=0;c<e.cands.length;c++)if((i=e.cands[c]).d=(i.w||1)/t,!(e.index>=c)){if(!(i.d<=n)&&(r=e.cands[c-1],a=i.d,d=n,s=u=void 0,r&&r.d&&(s=.7<d?.6:.4,r.d>=d||((u=Math.pow(r.d-s,1.6)||.1)<.1?u=.1:3<u&&(u=3),!(r.d+(a-d)*u<d)))))break;e.cSrcset.push(i.c),e.index=c}}},f=function(e,t,n,i,r){var a,d,u,s,c=e[r];if(c.width=t,c.picture&&(d=e.parentNode))for(s=0,u=(a=d.getElementsByTagName("source")).length;s<u;s++)g(a[s],t,n,i,r);g(e,t,n,i,r)},m=function(e){var t=e.getAttribute("data-optimumx")||e.getAttribute("data-maxdpr");return!t&&c.constrainPixelDensity&&(t="auto"),t=t&&("auto"==t?c.getOptimumX(e):parseFloat(t,10))},a=function(){s&&!s.getOptimumX&&(s.getX=m,s.pWS=r,n.removeEventListener("lazybeforeunveil",a))},n.addEventListener("lazybeforeunveil",a),setTimeout(a),"function"!=typeof(c=s&&s.cfg).getOptimumX&&(c.getOptimumX=function(){var e=t.devicePixelRatio||1;return 2.6<e?e*=.6:1.9<e?e*=.8:e-=.01,Math.min(Math.round(100*e)/100,2)}),t.devicePixelRatio&&addEventListener("lazybeforesizes",function(e){var t,n,i,r,a,d,u;e.detail.instance==s&&(a=e.target,u=(d=e.detail).dataAttr,e.defaultPrevented||!(t=m(a))||t>=devicePixelRatio||(!u||!a._lazyOptimumx||d.reloaded||c.unloadedClass&&s.hC(a,c.unloadedClass)||(a._lazyOptimumx=null),n=l(a,"_lazyOptimumx"),(i=d.width)&&(n.width||0)<i&&(r=u?s.cfg.srcsetAttr:"srcset",s.rAF(function(){f(a,i,t,r,"_lazyOptimumx")}))))}))});