UNPKG

picturefill

Version:
5 lines 1.66 kB
/*! picturefill - v3.0.2 - 2016-02-12 * https://scottjehl.github.io/picturefill/ * Copyright (c) 2016 https://github.com/scottjehl/picturefill/blob/master/Authors.txt; Licensed MIT */ !function(a){"use strict";var b,c=0,d=function(){window.picturefill&&a(window.picturefill),(window.picturefill||c>9999)&&clearInterval(b),c++};b=setInterval(d,8),d()}(function(a,b){"use strict";var c=window.document,d=a._,e={},f=d.cfg,g="currentSrc",h=function(a,b,c){var d=c.curCan;a&&b.setAttribute("width",parseInt(a/d.res,10))},i=function(a,b,d){var f,i,j;a in e?h(e[a],b,d):(j=function(){d.pendingURLSize=null,f.onload=null,f.onerror=null,b=null,f=null},d.pendingURLSize=a,i=d.curCan,i.w&&h(i.w,b,d),f=c.createElement("img"),f.onload=function(){if(e[a]=f.naturalWidth||f.width,!e[a])try{c.body.appendChild(f),e[a]=f.offsetWidth||f.naturalWidth||f.width,c.body.removeChild(f)}catch(i){}a===b[g]&&h(e[a],b,d),j()},f.onerror=j,f.src=a,f&&f.complete&&f.onload())},j=function(){var a,b,e=function(){var e,f,g,h=c.getElementsByTagName("img"),i={elements:[]};for(d.setupRun(i),a=!1,clearTimeout(b),e=0,f=h.length;f>e;e++)g=h[e][d.ns],g&&g.curCan&&(d.setRes.res(g.curCan,g.curCan.set.sizes),d.setSize(h[e]));d.teardownRun(i)};return function(){!a&&f.addSize&&(a=!0,clearTimeout(b),b=setTimeout(e))}}();g in c.createElement("img")||(g="src"),d.setSize=function(a){var c,e=a[d.ns],h=e.curCan;e.dims===b&&(e.dims=a.getAttribute("height")&&a.getAttribute("width")),f.addSize&&h&&!e.dims&&(c=d.makeUrl(h.url),c===a[g]&&c!==e.pendingURLSize&&i(c,a,e))},window.addEventListener&&!d.supPicture&&addEventListener("resize",j,!1),"addSize"in f?f.addSize=!!f.addSize:f.addSize=!0,j()});