-
Notifications
You must be signed in to change notification settings - Fork 10
/
img.srcset.min.js
5 lines (4 loc) · 1.34 KB
/
img.srcset.min.js
1
2
3
4
5
/* imgsrcset - Img srcset polyfill for resolution responsive images. Authors & copyright (c) 2012: WebLinc, David Knight. */
(function(c){var s=c.document.documentElement,l=0,m=[],d="",h=c.addEventListener||(d="on")&&c.attachEvent,v=c.removeEventListener||c.detachEvent,w=/[^\s]+/g,x=/[0-9\.]+/g,t=0,g=function(){clearTimeout(t);t=setTimeout(function(){var b=null,e=l-1,d=e,a=!1;do if(b=m[d-e],b.element.parentNode){var a=b.media,a=-1!==a.indexOf(",")&&a.split(",")||[a],f=a.length-1,h=f,g=null,k=0,n="",p="";if(0>f)a=void 0;else{do{g=a[h-f].match(w)||[];for(k=g.length;k--;){var j=g[k],q=0,r=0;if(0<k){if(q=-1!==j.indexOf("w")&&
(c.innerWidth||s.clientWidth)||-1!==j.indexOf("h")&&(c.innerHeight||s.clientHeight)||-1!==j.indexOf("x")&&(c.devicePixelRatio||1),r=Number(j.match(x)),q&&r&&r>q)break}else n=j,p=a[f]}}while(f--);a=n&&p&&{src:n,media:p}||!1}a&&b.matches!==a.media?(b.matches=a.media,b.element.src=a.src):a||(b.matches=!1,b.src&&(b.element.src=b.src))}else l--,b.splice(e,1);while(e--)},10)},u=function(){v(d+"load",u);c.Imgsrcset.parse();g();h(d+"resize",g);h(d+"orientationchange",g)};c.Imgsrcset={parse:function(){m=[];
var b=c.document.getElementsByTagName("img")||[],e=b.length-1,d=e,a=null,f="";do a=b[d-e],(f=a.getAttribute("srcset")||"")&&(l=m.push({element:a,media:f,matches:!1,src:a.getAttribute("src")||""}));while(e--)}};h(d+"load",u)})(window);