/
jquery.lazyloadxt.srcset.min.js
2 lines (2 loc) · 1.15 KB
/
jquery.lazyloadxt.srcset.min.js
1
2
/* Lazy Load XT 0.8.9-alpha | MIT License */
!function(a,b,c,d){function e(b,c){return Math[c].apply(null,a.map(b,function(a){return a[h]}))}function f(a){return a[h]>=s[h]||a[h]===i}function g(a){return a[h]===i}var h,i,j=a.lazyLoadXT,k=function(){return"srcset"in new Image}(),l=/^\s*(\S*)/,m=/\S\s+(\d+)w/,n=/\S\s+(\d+)h/,o=/\S\s+([\d\.]+)x/,p=[0,1/0],q=[0,1],r={srcsetAttr:"data-srcset",srcsetExtended:!0,srcsetBaseAttr:"data-srcset-base",srcsetExtAttr:"data-srcset-ext"},s={w:0,h:0,x:0};for(h in r)j[h]===d&&(j[h]=r[h]);a(c).on("lazyshow","img",function(d,r){var t=r.attr(j.srcsetAttr);if(t)if(!j.srcsetExtended&&k)r.attr("srcset",t);else{var u=t.split(",").map(function(a){return{url:l.exec(a)[1],w:parseFloat((m.exec(a)||p)[1]),h:parseFloat((n.exec(a)||p)[1]),x:parseFloat((o.exec(a)||q)[1])}});if(u.length){var v,w,x=c.documentElement;s={w:b.innerWidth||x.clientWidth,h:b.innerHeight||x.clientHeight,x:b.devicePixelRatio||1};for(v in s)h=v,i=e(u,"max"),u=a.grep(u,f);for(v in s)h=v,i=e(u,"min"),u=a.grep(u,g);w=u[0].url,j.srcsetExtended&&(w=(r.attr(j.srcsetBaseAttr)||"")+w+(r.attr(j.srcsetExtAttr)||"")),r.attr("src",w)}}})}(window.jQuery||window.Zepto,window,document);