diff --git a/README.md b/README.md
index b28c849d..614b0ca2 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
#lazysizes
-**lazysizes** is a fast (jank-free) lazyloader for images (including responsive images), iframes, scripts/widgets and much more. It may become also your number one tool to integrate responsive images. Due to the fact that it can also automatically calculate the ``sizes`` attribute for your responsive images, it helps to separate layout (CSS) from content/structure (HTML) and makes integrating responsive images into any environment simply simple.
+**lazysizes** is a fast (jank-free) and self-initializing lazyloader for images (including responsive images), iframes, scripts/widgets and much more. It may become also your number one tool to integrate responsive images. Due to the fact that it can also automatically calculate the ``sizes`` attribute for your responsive images, it helps to separate layout (CSS) from content/structure (HTML) and makes integrating responsive images into any environment simply simple.
##How to
@@ -48,7 +48,7 @@
##[Demo with code examples](http://afarkas.github.io/lazysizes/#examples)
Can be seen [here](http://afarkas.github.io/lazysizes/#examples).
-##About responsive image support
+##About responsive image support (``picture`` and/or ``srcset``)
For full cross browser responsive image support you must either use a polyfill like [respimage (recommended) (srcset and picture polyfill)](https://github.com/aFarkas/respimage) or [picturefill](https://github.com/scottjehl/picturefill) or use the [responsive image on demand plugin](plugins/rias).
##More about the API
@@ -274,11 +274,20 @@ document.addEventListener('lazybeforeunveil', function(e){
})
;
});
+
+document.addEventListener('lazybeforeunveil', function(e){
+ $(e.target)
+ .filter('.chart')
+ .chart({
+ animate: true
+ })
+ ;
+});
-
+
```
* ``lazybeforesizes``: This event will be fired on each element with the ``data-sizes="auto"`` attribute right before the calculated ``sizes`` attribute will be set. The ``event.details.width`` property is set to the calculated width of the element and can be changed to any number. In case the event is ``defaultPrevented`` the ``sizes`` attribute won't be set.
diff --git a/lazysizes.js b/lazysizes.js
index 61e3ed4a..41a94bff 100644
--- a/lazysizes.js
+++ b/lazysizes.js
@@ -124,7 +124,7 @@
};
var loader = (function(){
- var lazyloadElems, preloadElems, isPreloadAllowed, isCompleted, resetPreloadingTimer;
+ var lazyloadElems, preloadElems, isPreloadAllowed, isCompleted, resetPreloadingTimer, runThrough;
var eLvW, elvH, eLtop, eLleft, eLright, eLbottom;
@@ -228,8 +228,9 @@
loadedSomething = true;
} else {
- if(Date.now() - start > 6){
+ if(!runThrough && Date.now() - start > 3){
checkElementsIndex++;
+ runThrough = true;
throttledCheckElements();
return;
}
@@ -245,6 +246,7 @@
}
checkElementsIndex = 0;
+ runThrough = false;
lowRuns++;
@@ -425,9 +427,11 @@
document.addEventListener(evt, throttledCheckElements, true);
});
- addEventListener('load', onload, false);
+ if(!(isCompleted = /d$|^c/.test(document.readyState))){
+ addEventListener('load', onload, false);
+ document.addEventListener('DOMContentLoaded', throttledCheckElements, false);
+ }
- document.addEventListener('DOMContentLoaded', throttledCheckElements, false);
setTimeout(allowPreload, 666);
throttledCheckElements();
};
@@ -528,10 +532,8 @@
window.lazySizesConfig = lazySizesConfig;
- setTimeout(function(){
- autoSizer.init();
- loader.init();
- });
+ autoSizer.init();
+ loader.init();
})();
diff --git a/lazysizes.min.js b/lazysizes.min.js
index 43d73dee..e41b7967 100644
--- a/lazysizes.min.js
+++ b/lazysizes.min.js
@@ -1,3 +1,3 @@
/*! lazysizes - v0.8.0-RC1 - 2015-01-17
Licensed MIT */
-!function(a,b){a.lazySizes=b(a,a.document),"function"==typeof define&&define.amd&&define(a.lazySizes)}(window,function(a,b){"use strict";if(b.getElementsByClassName){var c,d=b.documentElement,e=/^picture$/i,f=["load","error","lazyincluded","_lazyloaded"],g=function(a,b){var c=new RegExp("(\\s|^)"+b+"(\\s|$)");return a.className.match(c)&&c},h=function(a,b){g(a,b)||(a.className+=" "+b)},i=function(a,b){var c;(c=g(a,b))&&(a.className=a.className.replace(c," "))},j=function(a,b,c){var d=c?"addEventListener":"removeEventListener";c&&j(a,b),f.forEach(function(c){a[d](c,b)})},k=function(a,c,d){var e=b.createEvent("Event");return e.initEvent(c,!0,!0),e.details=d||{},a.dispatchEvent(e),e},l=function(b,c){var d;a.HTMLPictureElement||(a.picturefill?picturefill({reevaluate:!0,reparse:!0,elements:[b]}):a.respimage?(c&&(d=b[respimage._.ns],d&&(d[c.srcset?"srcset":"src"]=void 0)),respimage({reparse:!0,elements:[b]})):c&&c.src&&(b.src=c.src))},m=function(a,b){return getComputedStyle(a,null)[b]},n=function(a,d){var e,f;for(a._lazysizesWidth||(f=a.getAttribute("alt"),a.alt=""),e=a.offsetWidth;eJ||!a.target)&&(J=0)},M=function(a,c){var e,f=a,g="hidden"!=m(a,"visibility");for(u-=c,x+=c,v-=c,w+=c;g&&(f=f.offsetParent)&&f!=d&&f!=b.body;)g=p&&4>J||(m(f,"opacity")||1)>0,g&&"visible"!=m(f,"overflow")&&(e=f.getBoundingClientRect(),g=w>e.left-1&&ve.top-1&&um;m++,K++)if((i=f[m].getAttribute("data-expand"))&&(e=1*i)||(e=G),!(J>6&&(!i||"src"in f[m])))if(J>3&&e>D&&(e=D),j!==e&&(s=innerWidth+e,t=innerHeight+e,h=-1*e,j=e),a=f[m].getBoundingClientRect(),(x=a.bottom)>=h&&(u=a.top)<=t&&(w=a.right)>=h&&(v=a.left)<=s&&(x||w||v||u)&&(p&&G==E&&3>J&&4>I&&!i||M(f[m],e)))K--,l++,R(f[m]),d=!0;else{if(Date.now()-l>6)return K++,void O();!d&&p&&!b&&3>J&&4>I&&(g[0]||c.preloadAfterLoad)&&(g[0]||!i&&(x||w||v||u||"auto"!=f[m].getAttribute(c.sizesAttr)))&&(b=g[0]||f[m])}K=0,I++,F>G&&2>J&&I>4?(G=F,I=0,O()):G!=E&&(G=E),b&&!d&&R(b)}},O=o(N),P=function(a){h(a.target,c.loadedClass),i(a.target,c.loadingClass),j(a.target,P)},Q=function(a,b){try{a.contentWindow.location.replace(b)}catch(c){a.setAttribute("src",b)}},R=function(a,b){var d,f,g,m,n,o,s,t,u,v,w,x=a.currentSrc||a.src,y=B.test(a.nodeName);if(A||p||!y||!x||a.complete){if(!(v=k(a,"lazybeforeunveil",{force:!!b})).defaultPrevented){if(n=a.getAttribute(c.sizesAttr)||a.getAttribute("sizes"),n&&("auto"==n?q.updateElem(a,!0):a.setAttribute("sizes",n)),s=a.getAttribute(c.srcsetAttr),o=a.getAttribute(c.srcAttr),w=v.details.firesLoad||"src"in a&&(s||o),w&&(J++,j(a,L,!0),clearTimeout(r),r=setTimeout(L,3e3),y&&(t=a.parentNode,u=e.test(t.nodeName||""))),s||o){if(u)for(d=t.getElementsByTagName("source"),f=0,g=d.length;g>f;f++)m=d[f].getAttribute(c.srcsetAttr),m&&d[f].setAttribute("srcset",m);s?(a.setAttribute("srcset",s),z&&n&&a.removeAttribute("src")):o&&(C.test(a.nodeName)?Q(a,o):a.setAttribute("src",o))}c.addClasses&&(h(a,c.loadingClass),j(a,P,!0))}setTimeout(function(){"auto"==n&&h(a,c.autosizesClass),(s||n)&&l(a,{srcset:s,src:o}),i(a,c.lazyClass),(!w||a.complete&&x==(a.currentSrc||a.src))&&(w&&L({target:a}),c.addClasses&&P({target:a})),a=null})}},S=function(){n&&!H&&(E=Math.max(Math.min(c.expand||c.threshold||150,300),30),F=Math.min(4*E,Math.max(1.1*innerHeight,d.clientHeight,3*E))),H=!0},T=function(){n=!0,H=!1},U=function(){T(),p=!0,O(!0)},V=function(){f=b.getElementsByClassName(c.lazyClass),g=b.getElementsByClassName(c.lazyClass+" "+c.preloadClass),c.scroll&&addEventListener("scroll",O,!0),addEventListener("resize",function(){H=!1,O()},!1),a.MutationObserver?new MutationObserver(O).observe(d,{childList:!0,subtree:!0,attributes:!0}):(d.addEventListener("DOMNodeInserted",O,!0),d.addEventListener("DOMAttrModified",O,!0)),addEventListener("hashchange",O,!0),["transitionstart","transitionend","load","focus","mouseover","animationend"].forEach(function(a){b.addEventListener(a,O,!0)}),addEventListener("load",U,!1),b.addEventListener("DOMContentLoaded",O,!1),setTimeout(T,666),O()};return{init:V,checkElems:O,unveil:R}}(),q=function(){var a,d=function(a,b){var d,f,g,h,i,j=a.parentNode;if(j&&(d=n(a,j),i=k(a,"lazybeforesizes",{width:d,dataAttr:!!b}),!i.defaultPrevented&&(d=i.details.width,d&&d!==a._lazysizesWidth&&(!c.onlyLargerSizes||!a._lazysizesWidth||a._lazysizesWidthg;g++)f[g].setAttribute("sizes",d);i.details.dataAttr||l(a)}},f=function(){var b,c=a.length;if(c)for(b=0;c>b;b++)d(a[b])},g=o(f),h=function(){a=b.getElementsByClassName(c.autosizesClass),addEventListener("resize",g,!1)};return{init:h,checkElems:g,updateElem:d}}();return function(){var b,d={lazyClass:"lazyload",loadedClass:"lazyloaded",loadingClass:"lazyloading",preloadClass:"lazypreload",scroll:!0,autosizesClass:"lazyautosizes",srcAttr:"data-src",srcsetAttr:"data-srcset",sizesAttr:"data-sizes",onlyLargerSizes:!0,minSize:40};c=a.lazySizesConfig||{};for(b in d)b in c||(c[b]=d[b]);a.lazySizesConfig=c,setTimeout(function(){q.init(),p.init()})}(),{cfg:c,autoSizer:q,loader:p,updateAllSizes:q.updateElems,updateAllLazy:p.checkElems,unveilLazy:p.unveil,uS:q.updateElem,uP:l,aC:h,rC:i,hC:g,fire:k,gW:n}}});
\ No newline at end of file
+!function(a,b){a.lazySizes=b(a,a.document),"function"==typeof define&&define.amd&&define(a.lazySizes)}(window,function(a,b){"use strict";if(b.getElementsByClassName){var c,d=b.documentElement,e=/^picture$/i,f=["load","error","lazyincluded","_lazyloaded"],g=function(a,b){var c=new RegExp("(\\s|^)"+b+"(\\s|$)");return a.className.match(c)&&c},h=function(a,b){g(a,b)||(a.className+=" "+b)},i=function(a,b){var c;(c=g(a,b))&&(a.className=a.className.replace(c," "))},j=function(a,b,c){var d=c?"addEventListener":"removeEventListener";c&&j(a,b),f.forEach(function(c){a[d](c,b)})},k=function(a,c,d){var e=b.createEvent("Event");return e.initEvent(c,!0,!0),e.details=d||{},a.dispatchEvent(e),e},l=function(b,c){var d;a.HTMLPictureElement||(a.picturefill?picturefill({reevaluate:!0,reparse:!0,elements:[b]}):a.respimage?(c&&(d=b[respimage._.ns],d&&(d[c.srcset?"srcset":"src"]=void 0)),respimage({reparse:!0,elements:[b]})):c&&c.src&&(b.src=c.src))},m=function(a,b){return getComputedStyle(a,null)[b]},n=function(a,d){var e,f;for(a._lazysizesWidth||(f=a.getAttribute("alt"),a.alt=""),e=a.offsetWidth;eK||!a.target)&&(K=0)},N=function(a,c){var e,f=a,g="hidden"!=m(a,"visibility");for(v-=c,y+=c,w-=c,x+=c;g&&(f=f.offsetParent)&&f!=d&&f!=b.body;)g=p&&4>K||(m(f,"opacity")||1)>0,g&&"visible"!=m(f,"overflow")&&(e=f.getBoundingClientRect(),g=x>e.left-1&&we.top-1&&vm;m++,L++)if((i=f[m].getAttribute("data-expand"))&&(e=1*i)||(e=H),!(K>6&&(!i||"src"in f[m])))if(K>3&&e>E&&(e=E),j!==e&&(t=innerWidth+e,u=innerHeight+e,h=-1*e,j=e),a=f[m].getBoundingClientRect(),(y=a.bottom)>=h&&(v=a.top)<=u&&(x=a.right)>=h&&(w=a.left)<=t&&(y||x||w||v)&&(p&&H==F&&3>K&&4>J&&!i||N(f[m],e)))L--,l++,S(f[m]),d=!0;else{if(!s&&Date.now()-l>3)return L++,s=!0,void P();!d&&p&&!b&&3>K&&4>J&&(g[0]||c.preloadAfterLoad)&&(g[0]||!i&&(y||x||w||v||"auto"!=f[m].getAttribute(c.sizesAttr)))&&(b=g[0]||f[m])}L=0,s=!1,J++,G>H&&2>K&&J>4?(H=G,J=0,P()):H!=F&&(H=F),b&&!d&&S(b)}},P=o(O),Q=function(a){h(a.target,c.loadedClass),i(a.target,c.loadingClass),j(a.target,Q)},R=function(a,b){try{a.contentWindow.location.replace(b)}catch(c){a.setAttribute("src",b)}},S=function(a,b){var d,f,g,m,n,o,s,t,u,v,w,x=a.currentSrc||a.src,y=C.test(a.nodeName);if(B||p||!y||!x||a.complete){if(!(v=k(a,"lazybeforeunveil",{force:!!b})).defaultPrevented){if(n=a.getAttribute(c.sizesAttr)||a.getAttribute("sizes"),n&&("auto"==n?q.updateElem(a,!0):a.setAttribute("sizes",n)),s=a.getAttribute(c.srcsetAttr),o=a.getAttribute(c.srcAttr),w=v.details.firesLoad||"src"in a&&(s||o),w&&(K++,j(a,M,!0),clearTimeout(r),r=setTimeout(M,3e3),y&&(t=a.parentNode,u=e.test(t.nodeName||""))),s||o){if(u)for(d=t.getElementsByTagName("source"),f=0,g=d.length;g>f;f++)m=d[f].getAttribute(c.srcsetAttr),m&&d[f].setAttribute("srcset",m);s?(a.setAttribute("srcset",s),A&&n&&a.removeAttribute("src")):o&&(D.test(a.nodeName)?R(a,o):a.setAttribute("src",o))}c.addClasses&&(h(a,c.loadingClass),j(a,Q,!0))}setTimeout(function(){"auto"==n&&h(a,c.autosizesClass),(s||n)&&l(a,{srcset:s,src:o}),i(a,c.lazyClass),(!w||a.complete&&x==(a.currentSrc||a.src))&&(w&&M({target:a}),c.addClasses&&Q({target:a})),a=null})}},T=function(){n&&!I&&(F=Math.max(Math.min(c.expand||c.threshold||150,300),30),G=Math.min(4*F,Math.max(1.1*innerHeight,d.clientHeight,3*F))),I=!0},U=function(){n=!0,I=!1},V=function(){U(),p=!0,P(!0)},W=function(){f=b.getElementsByClassName(c.lazyClass),g=b.getElementsByClassName(c.lazyClass+" "+c.preloadClass),c.scroll&&addEventListener("scroll",P,!0),addEventListener("resize",function(){I=!1,P()},!1),a.MutationObserver?new MutationObserver(P).observe(d,{childList:!0,subtree:!0,attributes:!0}):(d.addEventListener("DOMNodeInserted",P,!0),d.addEventListener("DOMAttrModified",P,!0)),addEventListener("hashchange",P,!0),["transitionstart","transitionend","load","focus","mouseover","animationend"].forEach(function(a){b.addEventListener(a,P,!0)}),(p=/d$|^c/.test(b.readyState))||(addEventListener("load",V,!1),b.addEventListener("DOMContentLoaded",P,!1)),setTimeout(U,666),P()};return{init:W,checkElems:P,unveil:S}}(),q=function(){var a,d=function(a,b){var d,f,g,h,i,j=a.parentNode;if(j&&(d=n(a,j),i=k(a,"lazybeforesizes",{width:d,dataAttr:!!b}),!i.defaultPrevented&&(d=i.details.width,d&&d!==a._lazysizesWidth&&(!c.onlyLargerSizes||!a._lazysizesWidth||a._lazysizesWidthg;g++)f[g].setAttribute("sizes",d);i.details.dataAttr||l(a)}},f=function(){var b,c=a.length;if(c)for(b=0;c>b;b++)d(a[b])},g=o(f),h=function(){a=b.getElementsByClassName(c.autosizesClass),addEventListener("resize",g,!1)};return{init:h,checkElems:g,updateElem:d}}();return function(){var b,d={lazyClass:"lazyload",loadedClass:"lazyloaded",loadingClass:"lazyloading",preloadClass:"lazypreload",scroll:!0,autosizesClass:"lazyautosizes",srcAttr:"data-src",srcsetAttr:"data-srcset",sizesAttr:"data-sizes",onlyLargerSizes:!0,minSize:40};c=a.lazySizesConfig||{};for(b in d)b in c||(c[b]=d[b]);a.lazySizesConfig=c,q.init(),p.init()}(),{cfg:c,autoSizer:q,loader:p,updateAllSizes:q.updateElems,updateAllLazy:p.checkElems,unveilLazy:p.unveil,uS:q.updateElem,uP:l,aC:h,rC:i,hC:g,fire:k,gW:n}}});
\ No newline at end of file