Tema: FF, jscript ir <link onload>
Autorius: flegmatoid
Data: 2010-01-13 10:48:41
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=windows-1257" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.18854">
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT size=2 face=Arial>sveiki,</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>yra poreikis&nbsp;dinamiskai uzloadinti keleta 
css'u ir js'u, jau baigtame loadinti dokumente.</FONT></DIV>
<DIV><FONT size=2 face=Arial>T.y. pradzioje loadiname css'a, po to - eileje 
esanty js'a. Sekoje g.b. nuo vieno iki keliolikos failu (mano atveju). Tikslas - 
isvengti race condition'u.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>&lt;script&gt; objektams pasidariau toki method'a, 
kuris lyg ir veikia (FF only realizacija kolkas), gi po FF &lt;link&gt; 
objektai&nbsp;irgi palaiko onload event'a, taciau jis "neissauna"!</FONT></DIV>
<DIV><FONT size=2><FONT face=Arial>("fire "load" event on stylesheet linking 
elements when the sheet load finishes" - </FONT><A 
href="https://bugzilla.mozilla.org/show_bug.cgi?id=185236"><FONT 
face=Arial>https://bugzilla.mozilla.org/show_bug.cgi?id=185236</FONT></A><FONT 
face=Arial>)</FONT></FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>kas matet/girdejot/turit panasu sprendima (ar seip 
minciu)&nbsp;stylesheet'u loadinimui - padekit!</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>dabar kaip ir tupikas - galvojau pradzioje 
&lt;head&gt; vaikus skaiciuoti ir pastebejus pokyti imituoti "onload'a" - wrong 
way.</FONT></DIV>
<DIV><FONT size=2 face=Arial>siuo metu&nbsp;bandau document.styleSheets stebeti, 
bet ten isvis mistika -&nbsp;matau pastoviai kintanti vaiku skaiciu - 
2;0;3;0;5;0 (loadinant keleta normaliu css'u ir viena dideli (viduje *.php failo 
virsuje sleep(20) ideta pvz)).</FONT></DIV>
<DIV><FONT size=2 
face="Courier New">_________________________________________________________</FONT></DIV>
<DIV><FONT size=2 face="Courier New"></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face="Courier New">var qLoader={<BR>&nbsp; 
queue:false,<BR>&nbsp; load: function () {<BR>&nbsp;&nbsp;&nbsp; if (!this.queue 
|| this.queue.length==0) return;&nbsp;&nbsp;&nbsp;</FONT></DIV>
<DIV><FONT size=2><BR><FONT face="Courier New">&nbsp;&nbsp;&nbsp; var 
d=document;<BR>&nbsp;&nbsp;&nbsp; var head = 
d.getElementsByTagName('head')[0];<BR>&nbsp;&nbsp;&nbsp; var 
url=this.queue.shift();</FONT></FONT></DIV>
<DIV><FONT size=2><BR><FONT face="Courier New">&nbsp;&nbsp;&nbsp; if 
(url.match(/js(b?)/g)) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var obj = 
d.createElement('script');<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; obj.src = 
url;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
obj.type='text/javascript';<BR>&nbsp;&nbsp;&nbsp; } else if (url.match(/css/g)) 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var obj = 
d.createElement('link');<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; obj.href = 
url;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
obj.type='text/css';<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
obj.rel='stylesheet';<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; 
<BR>&nbsp;&nbsp;&nbsp; obj.onload=function() {//sis eventas&nbsp;suveikia 
tik&nbsp;&lt;script&gt;, bet ne &lt;link&gt; 
objektams<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
qLoader.load();<BR>&nbsp;&nbsp;&nbsp; }</FONT></FONT></DIV><FONT size=2 
face="Courier New">
<DIV><BR>&nbsp;&nbsp;&nbsp; head.appendChild(obj);<BR>&nbsp; }<BR>}</DIV>
<DIV>&nbsp;</DIV>
<DIV>var objects=[</DIV>
<DIV>'/js/test1.js',</DIV>
<DIV>'/ts/test2.js',</DIV>
<DIV>'/css/style2.css'</DIV>
<DIV>]<BR></DIV>
<DIV>qLoader.queue=objects;</DIV>
<DIV>qLoader.load();</FONT></DIV></BODY></HTML>