Skip to content
Browse files

inserting `scriptElm`s before the first <base> element found - to avo…

…id crashes in MSIE 6 (see: http://dev.jquery.com/ticket/2709 )
  • Loading branch information...
1 parent 473a2d0 commit fe4b73f8257f24d0f02064ac34e7c3e37729c2a7 @maranomynet committed Feb 8, 2010
Showing with 10 additions and 4 deletions.
  1. +9 −3 req-source.js
  2. +1 −1 req.js
View
12 req-source.js
@@ -27,7 +27,7 @@
-----------------------------------------------------------------------------
TODO (developer's notes):
- * Support also loading CSS files.
+ * Support also loading CSS files. (maybe ??)
* Look into doing parallel downloading (while ensuring execution order)
with DOM Node injection in normal browsers but using 'defer' in MSIE
As per suggestions in this article:
@@ -38,7 +38,7 @@
*/
/*
- Attempt to apply document.readyState support in FF3.5 and older.
+ First: Attempt to apply document.readyState support in FF3.5 and older.
See more:
* http://webreflection.blogspot.com/2009/11/195-chars-to-help-lazy-loading.html
* http://groups.google.com/group/jquery-dev/browse_thread/thread/5aba1a1c2a7e53a7/e76736baf202f6e1
@@ -279,7 +279,11 @@
_processNext();
}
};
- _headElm.appendChild(scriptElm);
+ // NOTE: if we were to use a simple `.insertBefore(scriptElm, _headElm.firstChild)` like done by jQuery
+ // we'd get all the injected scriptElms in reverse order which would make debugging confusing.
+ _firstBaseElm ?
+ _headElm.insertBefore(scriptElm, _firstBaseElm): // silly hack, needed to avoid crash in MSIE 6.0 (see: http://dev.jquery.com/ticket/2709 )
+ _headElm.appendChild(scriptElm);
// return without recursing ... because now we're playing The Waiting Game with the <script> we've just inserted
return;
}
@@ -296,6 +300,7 @@
_isRunning, // flag to indicate that _processNext is indeed running - only waiting for a <script> to load.
_headElm, // cached reference to the <head> element
+ _firstBaseElm, // reference to the first <base> element in the document - needed to avoid crash in MSIE 6.0 (see: http://dev.jquery.com/ticket/2709 )
_baseUrl, // cached *normalized* value of Req.baseUrl
_joinUrl, // cached *normalized* value of Req.joinUrl
s, // cached value of Req.urlToken
@@ -318,6 +323,7 @@
// find + store/cache the <head> element
_headElm = _headElm || document.getElementsByTagName('head')[0];
+ _firstBaseElm = _firstBaseElm || _headElm.getElementsByTagName('base')[0];
// prep (normalize) the assets in the arguments array.
var _queueStub = _prepQueue( [].slice.call(arguments, 0) ),
i = _queueStub.length;
View
2 req.js
@@ -1,3 +1,3 @@
// Req.js v1.0 - MIT/GPL Licensed - More info: http://mar.anomynet/entries/2009/10/20/23.39.22/
(function(b,c,e,a){if(b[c]==null&&b[e]){b[c]="loading";b[e](a,e=function(){b[c]="complete";b.removeEventListener(a,e,!1)},!1)}})(document,"readyState","addEventListener","DOMContentLoaded");
-(function(l,x){var k=[],t='onreadystatechange',j='onload',u=function(e){var c,d=g.assets,a=g.fixUrl,f=[];for(var q=0,w=e.length;q<w;q++){var b=e[q];if(typeof b=='function'){f.push(b)}else if(b&&b!==true){if(b.charAt){c=b;b=d[c]||(d[c]=(d[a(c)]||{src:c}))}else{c=b.id||b.src;d[c]=d[c]||b}if(!b._1&&!b._0){b._1=1;if(!b._3){b._3=1;if(b.src){b.src=a(b.src);d[b.src]=b}var n=b.req;if(n&&n.charAt){b.req=[n]}}n&&f.push.apply(f,u(b.req));f.push(b)}}}return f},h=[],o=function(){var e,c=h.length;if(c>=g.joinLim){var d=[];while(c--){if(h[c].src){d.unshift(g.getJoinStub(h[c]))}}e={src:p.replace(i,d.join(g.joint||'')),_4:h};h=[]}else{e=h.shift();e._2=1}return e},r=function(){if(v=!!(k.length||h.length)){var a=k.shift()||o();if(typeof a=='function'){if(h.length){k.unshift(a);a=o()}else{a();a=l}}if(a&&!a._0){if(a.check&&a.check()){if(h.length&&a[j]){k.unshift(o(),a)}else{a._0=1;if(a[j]){a[j]();a[j]=l}}}else{if((a.join===true||!a.src)&&!a._2){h.push(a)}else{if(h.length&&!a._2){k.unshift(a);a=o()}if(a.src){var f=document.createElement('script');f.charset=a.charset||g.charset||l;f.src=a.src;f[j]=f[t]=function(){if(!f.readyState||/^(loaded|complete)$/.test(f.readyState)){f[t]=f[j]=l;var e=a._4||[a];for(var c=0,d;(d=e[c]);c++){d._0=1;d[j]&&d[j]();d[j]=l}r()}};s.appendChild(f);return}a._0=1}}}r()}},v,s,m,p,i,g=Req=function(e){i=i||g.urlToken||'%{s}';m=g.baseUrl||i;m+=m.indexOf(i)>-1?'':i;p=g.joinUrl||i;p+=p.indexOf(i)>-1?'':i;s=s||document.getElementsByTagName('head')[0];var c=u([].slice.call(arguments,0)),d=c.length;while(d--){delete c[d]._1}k[e===true?'push':'unshift'].apply(k,c);setTimeout(function(){if(!v){r()}},0)};g.joinLim=1;g.fixUrl=function(e){return/^(\.?\/|https?:)/.test(e)?e:m.replace(i,e)};g.getJoinStub=function(e){return e.src.replace(m.split(i)[0],'')};g.assets={}})(null);
+(function(l,y){var k=[],u='onreadystatechange',j='onload',v=function(e){var c,d=g.assets,a=g.fixUrl,f=[];for(var s=0,x=e.length;s<x;s++){var b=e[s];if(typeof b=='function'){f.push(b)}else if(b&&b!==true){if(b.charAt){c=b;b=d[c]||(d[c]=(d[a(c)]||{src:c}))}else{c=b.id||b.src;d[c]=d[c]||b}if(!b._1&&!b._0){b._1=1;if(!b._3){b._3=1;if(b.src){b.src=a(b.src);d[b.src]=b}var o=b.req;if(o&&o.charAt){b.req=[o]}}o&&f.push.apply(f,v(b.req));f.push(b)}}}return f},h=[],p=function(){var e,c=h.length;if(c>=g.joinLim){var d=[];while(c--){if(h[c].src){d.unshift(g.getJoinStub(h[c]))}}e={src:q.replace(i,d.join(g.joint||'')),_4:h};h=[]}else{e=h.shift();e._2=1}return e},t=function(){if(w=!!(k.length||h.length)){var a=k.shift()||p();if(typeof a=='function'){if(h.length){k.unshift(a);a=p()}else{a();a=l}}if(a&&!a._0){if(a.check&&a.check()){if(h.length&&a[j]){k.unshift(p(),a)}else{a._0=1;if(a[j]){a[j]();a[j]=l}}}else{if((a.join===true||!a.src)&&!a._2){h.push(a)}else{if(h.length&&!a._2){k.unshift(a);a=p()}if(a.src){var f=document.createElement('script');f.charset=a.charset||g.charset||l;f.src=a.src;f[j]=f[u]=function(){if(!f.readyState||/^(loaded|complete)$/.test(f.readyState)){f[u]=f[j]=l;var e=a._4||[a];for(var c=0,d;(d=e[c]);c++){d._0=1;d[j]&&d[j]();d[j]=l}t()}};r?m.insertBefore(f,r):m.appendChild(f);return}a._0=1}}}t()}},w,m,r,n,q,i,g=Req=function(e){i=i||g.urlToken||'%{s}';n=g.baseUrl||i;n+=n.indexOf(i)>-1?'':i;q=g.joinUrl||i;q+=q.indexOf(i)>-1?'':i;m=m||document.getElementsByTagName('head')[0];r=r||m.getElementsByTagName('base')[0];var c=v([].slice.call(arguments,0)),d=c.length;while(d--){delete c[d]._1}k[e===true?'push':'unshift'].apply(k,c);setTimeout(function(){if(!w){t()}},0)};g.joinLim=1;g.fixUrl=function(e){return/^(\.?\/|https?:)/.test(e)?e:n.replace(i,e)};g.getJoinStub=function(e){return e.src.replace(n.split(i)[0],'')};g.assets={}})(null);

0 comments on commit fe4b73f

Please sign in to comment.
Something went wrong with that request. Please try again.