-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpicturefill.js
1 lines (1 loc) · 935 Bytes
/
picturefill.js
1
(function(e){"use strict";e.picturefill=function(){var t=e.document.getElementsByTagName("span");for(var n=0,r=t.length;n<r;n++){if(t[n].getAttribute("data-picture")!==null){var i=t[n].getElementsByTagName("span"),s=[];for(var o=0,u=i.length;o<u;o++){var a=i[o].getAttribute("data-media");if(!a||e.matchMedia&&e.matchMedia(a).matches){s.push(i[o])}}var f=t[n].getElementsByTagName("img")[0];if(s.length){var l=s.pop();if(!f||f.parentNode.nodeName==="NOSCRIPT"){f=e.document.createElement("img");f.alt=t[n].getAttribute("data-alt")}f.src=l.getAttribute("data-src");l.appendChild(f)}else if(f){f.parentNode.removeChild(f)}}}};if(e.addEventListener){e.addEventListener("resize",e.picturefill,false);e.addEventListener("DOMContentLoaded",function(){e.picturefill();e.removeEventListener("load",e.picturefill,false)},false);e.addEventListener("load",e.picturefill,false)}else if(e.attachEvent){e.attachEvent("onload",e.picturefill)}})(this)