-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpicture.min.js
7 lines (6 loc) · 2.4 KB
/
picture.min.js
1
2
3
4
5
6
7
/* Picture v2.2.0 - Picture element polyfill for responsive images. Authors & copyright (c) 2013: WebLinc, David Knight. */
"HTMLPictureElement"in window||function(l){var r=l.document,k="",s=l.addEventListener||(k="on")&&l.attachEvent,p=l.removeEventListener||l.detachEvent,x=/[^\s]+/g,q=function(){p(k+"load",q);p(k+"DOMContentLoaded",q);l.Picture.parse()},v=function(e,d){var a=e.pictureImage;null===e.parentNode?d.mql.removeListener(d.listener):(a||(a=e.pictureImage=r.createElement("img"),a.alt=e.pictureAlt),d&&d.src!==e.pictureCurrentSrc&&(a.src=e.pictureCurrentSrc=d.src,d.element.appendChild(a)))},t=function(){var e=
r.getElementsByTagName("span");p(k+"resize",t);for(var d=0,a;"undefined"!==typeof(a=e[d]);d++)if("pictureSource"in a)for(var h=a.pictureSource.length-1,c;"undefined"!==typeof(c=a.pictureSource[h]);h--)c.listener||(c.listener=y(a,c),c.mql.addListener(c.listener))},y=function(e,d){return function(a){var h=e.pictureSource,c=d;a.matches||(c=h[h.join("").lastIndexOf("1")]);c&&v(e,c)}},u=function(e,d,a,h){return{element:e,src:d,mql:a,listener:h,toString:function(){return this.mql.matches?1:0}}},w=function(e,
d,a,h){a=0<=a.indexOf(",")&&a.split(",")||[a];for(var c=null,k=0,g;"undefined"!==typeof(g=a[k]);k++){var b=h||"all",f=g.match(x);g=f[0];var f=parseFloat(f[1],10),m=null;1<f&&(b=["(-webkit-min-device-pixel-ratio: "+f+")","(min-resolution: "+f+"dppx)","(min-resolution: "+96*f+"dpi)","not all"].join(" and "+b+", "));b&&(m=u(d,g,l.matchMedia(b),null),m.mql.matches&&(c=m),e.pictureSource.push(m))}return c};l.Picture={parse:function(){for(var e=r.getElementsByTagName("span"),d=0,a;"undefined"!==typeof(a=
e[d]);d++)if(null!==a.getAttribute("data-picture")&&!("pictureSource"in a)){var h=a.getElementsByTagName("span"),c=a.getAttribute("data-srcset"),n="",g=a.getElementsByTagName("img")[0],b=null,f=b=null;a.pictureSource=[];a.pictureImage=g&&"NOSCRIPT"!==g.parentNode.nodeName&&g;a.pictureAlt=a.getAttribute("data-alt")||g&&g.getAttribute("alt")||"picture";a.pictureCurrentSrc="";c?(b=w(a,a,c,""))&&(f=b):(n=a.getAttribute("data-src"))&&(f=u(a,n,null,null));if(!c&&!n)for(g=h.length-1;"undefined"!==typeof(b=
h[g]);g--){var m=b.getAttribute("data-media");(c=b.getAttribute("data-srcset"))?(b=w(a,b,c,m))&&(f=b):m&&(n=b.getAttribute("data-src"))&&(b=u(b,n,l.matchMedia(m),null),b.mql.matches&&(f=b),a.pictureSource.push(b))}f&&v(a,f)}p(k+"resize",t);s(k+"resize",t)}};s(k+"DOMContentLoaded",q);s(k+"load",q)}(window);