forked from aFarkas/lazysizes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ls.optimumx.min.js
3 lines (3 loc) · 3.08 KB
/
ls.optimumx.min.js
1
2
3
/*! lazysizes - v0.9.0 - 2015-02-06
Licensed MIT */
!function(a,b){"use strict";var c,d=/^picture$/i,e=b.documentElement,f=function(){var a,b=/(([^,\s].[^\s]+)\s+(\d+)w)/g,c=/\s+\d+h/g,d=function(b,c,d,e){a.push({c:c,u:d,w:1*e})};return function(e){return a=[],e.replace(c,"").replace(b,d),a}}(),g=function(){var a=function(a,b){return a.w-b.w},b=function(b,c,d){var e={srcset:b.getAttribute(lazySizes.cfg.srcsetAttr)||""},g=f(e.srcset);return Object.defineProperty(b,c,{value:e,writable:!0}),e.cands=g,e.index=0,e.dirty=!1,g[0]&&g[0].w?(d&&(e.index=g.length-1),g.sort(a),e.cSrcset=[g[e.index].c]):(e.cSrcset=e.srcset?[e.srcset]:[],e.cands=[]),e};return function(a,c){var e,f,g,h,i="_lazyMinx"==c;if(!a[c]&&(h=a.parentNode||{},a[c]=b(a,c,i),a[c].isImg=!0,d.test(h.nodeName||"")))for(a[c].picture=!0,e=h.getElementsByTagName("source"),f=0,g=e.length;g>f;f++)b(e[f],c,i).isImg=!1;return a[c]}}(),h={_lazyOptimumx:function(){var a=function(a,b,c){var d,e;return a&&a.w?a.w>c?!1:(d=1-a.w/c,e=b/c-1,0>e-d):!0};return function(b,c){var d,e;for(d=b.index+1;d<b.cands.length&&(e=b.cands[d],e.w<=c||a(b.cands[d-1],e.w,c));d++)b.cSrcset.push(e.c),b.index=d}}(),_lazyMinx:function(a,b){for(var c,d=a.index-1;d>-1&&(c=a.cands[d],c.w>=b);)a.cSrcset.push(c.c),a.index=d,d--}},i=function(){var a=function(a,b,c,d){var e,f=a[d];f&&(e=f.index,h[d](f,b),f.dirty&&e==f.index||(f.cSrcset.join(", "),a.setAttribute(c,f.cSrcset.join(", ")),f.dirty=!0,f.cSrcset.length>=f.cands.length&&(a.removeAttribute("data-optimumx"),a.removeAttribute("data-maxdpr"))))};return function(b,c,d,e){var f,g,h,i,j=b[e];if(j.width=c,j.picture&&(g=b.parentNode))for(f=g.getElementsByTagName("source"),i=0,h=f.length;h>i;i++)a(f[i],c,d,e);a(b,c,d,e)}}(),j=function(a){var b=a.getAttribute("data-optimumx")||a.getAttribute("data-maxdpr");return b&&(b="auto"==b?c.getOptimumX(a):parseFloat(b,10)),b},k=function(){a.lazySizes&&!a.lazySizes.getOptimumX&&(lazySizes.getX=j,lazySizes.pWS=f,e.removeEventListener("lazybeforeunveil",k))};e.addEventListener("lazybeforeunveil",k),setTimeout(k),c=a.lazySizes&&lazySizes.cfg||a.lazySizesConfig,c||(c={},a.lazySizesConfig=c),"function"!=typeof c.getOptimumX&&(c.getOptimumX=function(){var b=a.devicePixelRatio||1;return b>2.4?b*=.63:b>1.9?b*=.8:b>1.4&&(b*=.9),Math.min(Math.round(100*b)/100,2)}),a.devicePixelRatio&&(addEventListener("lazybeforesizes",function(a){var b,c,d,e;a.defaultPrevented||!(b=j(a.target))||b>=devicePixelRatio||(c=g(a.target,"_lazyOptimumx"),d=a.details.width*b,d&&(c.width||0)<d&&(e=a.details.dataAttr?lazySizes.cfg.srcsetAttr:"srcset",i(a.target,d,e,"_lazyOptimumx")))}),addEventListener("lazybeforesizes",function(a){var b,c,d,e;a.defaultPrevented||a.target._lazyOptimumx||!(b=1*a.target.getAttribute("data-minx"))||b+.2<devicePixelRatio||(c=g(a.target,"_lazyMinx"),b=Math.min(b,devicePixelRatio),d=a.details.width*b,d&&(c.width||0)<d&&(e=a.details.dataAttr?lazySizes.cfg.srcsetAttr:"srcset",i(a.target,d,e,"_lazyMinx"),a.target.removeAttribute("data-minx")))}),addEventListener("lazybeforeunveil",function(a){a.target._lazyOptimumx&&(a.target._lazyOptimumx=null),a.target._lazyMinx&&(a.target._lazyMinx=null)}))}(window,document);