Permalink
Browse files

Fix a Gecko CSS loading bug in the minified JS caused by an unwanted …

…Closure Compiler optimization. [Allex Wang]
  • Loading branch information...
1 parent a2e9573 commit fb63205e20c76061f616150264670acac6877b3f @rgrove committed Jul 5, 2011
Showing with 15 additions and 7 deletions.
  1. +4 −1 HISTORY
  2. +4 −4 lazyload-min.js
  3. +7 −2 lazyload.js
View
5 HISTORY
@@ -1,7 +1,10 @@
LazyLoad Changelog
================================================================================
-Version 2.0.3 (git)
+Version 2.0.3 (2011-07-05)
+ * Fixed a bug caused by an unwanted Closure Compiler optimization that broke
+ CSS load completion detection in Gecko when using the minified version of
+ LazyLoad. [Allex Wang]
* Fixed a race condition in which a URL could be removed from the "pending"
queue if it finished loading before other URLs in the same batch had been
added to the queue, resulting in the queue's length changing unexpectedly
View
8 lazyload-min.js
@@ -1,4 +1,4 @@
-LazyLoad=function(k){function p(c,a){var g=k.createElement(c),b;for(b in a)a.hasOwnProperty(b)&&g.setAttribute(b,a[b]);return g}function m(c){var a=l[c],b,f;if(a)b=a.callback,f=a.urls,f.shift(),i=0,f.length||(b&&b.call(a.context,a.obj),l[c]=null,n[c].length&&j(c))}function v(){var c=navigator.userAgent;b={async:k.createElement("script").async===!0};(b.webkit=/AppleWebKit\//.test(c))||(b.ie=/MSIE/.test(c))||(b.opera=/Opera/.test(c))||(b.gecko=/Gecko\//.test(c))||(b.unknown=!0)}function j(c,a,g,f,i){var j=
-function(){m(c)},o=c==="css",q=[],d,h,e,r;b||v();if(a)if(a=typeof a==="string"?[a]:a.concat(),o||b.async||b.gecko||b.opera)n[c].push({urls:a,callback:g,obj:f,context:i});else{d=0;for(h=a.length;d<h;++d)n[c].push({urls:[a[d]],callback:d===h-1?g:null,obj:f,context:i})}if(!l[c]&&(r=l[c]=n[c].shift())){s||(s=k.head||k.getElementsByTagName("head")[0]);a=r.urls;d=0;for(h=a.length;d<h;++d)g=a[d],o?e=b.gecko?p("style"):p("link",{href:g,rel:"stylesheet"}):(e=p("script",{src:g}),e.async=!1),e.className="lazyload",
-e.setAttribute("charset","utf-8"),b.ie&&!o?e.onreadystatechange=function(){if(/loaded|complete/.test(e.readyState))e.onreadystatechange=null,j()}:o&&(b.gecko||b.webkit)?b.webkit?(r.urls[d]=e.href,t()):(e.innerHTML='@import "'+g+'";',m("css")):e.onload=e.onerror=j,q.push(e);d=0;for(h=q.length;d<h;++d)s.appendChild(q[d])}}function t(){var c=l.css,a;if(c){for(a=u.length;--a>=0;)if(u[a].href===c.urls[0]){m("css");break}i+=1;c&&(i<200?setTimeout(t,50):m("css"))}}var b,s,l={},i=0,n={css:[],js:[]},u=k.styleSheets;
-return{css:function(c,a,b,f){j("css",c,a,b,f)},js:function(c,a,b,f){j("js",c,a,b,f)}}}(this.document);
+LazyLoad=function(k){function p(b,a){var g=k.createElement(b),c;for(c in a)a.hasOwnProperty(c)&&g.setAttribute(c,a[c]);return g}function l(b){var a=m[b],c,f;if(a)c=a.callback,f=a.urls,f.shift(),h=0,f.length||(c&&c.call(a.context,a.obj),m[b]=null,n[b].length&&j(b))}function w(){var b=navigator.userAgent;c={async:k.createElement("script").async===!0};(c.webkit=/AppleWebKit\//.test(b))||(c.ie=/MSIE/.test(b))||(c.opera=/Opera/.test(b))||(c.gecko=/Gecko\//.test(b))||(c.unknown=!0)}function j(b,a,g,f,h){var j=
+function(){l(b)},o=b==="css",q=[],d,i,e,r;c||w();if(a)if(a=typeof a==="string"?[a]:a.concat(),o||c.async||c.gecko||c.opera)n[b].push({urls:a,callback:g,obj:f,context:h});else{d=0;for(i=a.length;d<i;++d)n[b].push({urls:[a[d]],callback:d===i-1?g:null,obj:f,context:h})}if(!m[b]&&(r=m[b]=n[b].shift())){s||(s=k.head||k.getElementsByTagName("head")[0]);a=r.urls;d=0;for(i=a.length;d<i;++d)g=a[d],o?e=c.gecko?p("style"):p("link",{href:g,rel:"stylesheet"}):(e=p("script",{src:g}),e.async=!1),e.className="lazyload",
+e.setAttribute("charset","utf-8"),c.ie&&!o?e.onreadystatechange=function(){if(/loaded|complete/.test(e.readyState))e.onreadystatechange=null,j()}:o&&(c.gecko||c.webkit)?c.webkit?(r.urls[d]=e.href,t()):(e.innerHTML='@import "'+g+'";',u(e)):e.onload=e.onerror=j,q.push(e);d=0;for(i=q.length;d<i;++d)s.appendChild(q[d])}}function u(b){var a;try{a=!!b.sheet.cssRules}catch(c){h+=1;h<200?setTimeout(function(){u(b)},50):a&&l("css");return}l("css")}function t(){var b=m.css,a;if(b){for(a=v.length;--a>=0;)if(v[a].href===
+b.urls[0]){l("css");break}h+=1;b&&(h<200?setTimeout(t,50):l("css"))}}var c,s,m={},h=0,n={css:[],js:[]},v=k.styleSheets;return{css:function(b,a,c,f){j("css",b,a,c,f)},js:function(b,a,c,f){j("js",b,a,c,f)}}}(this.document);
View
9 lazyload.js
@@ -277,8 +277,13 @@ LazyLoad = (function (doc) {
@private
*/
function pollGecko(node) {
+ var hasRules;
+
try {
- node.sheet.cssRules;
+ // We don't really need to store this value or ever refer to it again, but
+ // if we don't store it, Closure Compiler assumes the code is useless and
+ // removes it.
+ hasRules = !!node.sheet.cssRules;
} catch (ex) {
// An exception means the stylesheet is still loading.
pollCount += 1;
@@ -289,7 +294,7 @@ LazyLoad = (function (doc) {
// We've been polling for 10 seconds and nothing's happened. Stop
// polling and finish the pending requests to avoid blocking further
// requests.
- finish('css');
+ hasRules && finish('css');
}
return;

0 comments on commit fb63205

Please sign in to comment.