1 // (c) Benoît PIN 2006-2007
8 function ScriptRegistry() {
9 this.loadedScripts
= new Object();
10 this.pendingScripts
= new Array();
11 this.HEAD
= document
.getElementsByTagName('head')[0];
12 this.isLoading
= false;
15 ScriptRegistry
.prototype.loadScript = function(scriptOb
) {
17 if (typeof(scriptOb
) == 'string')
20 scriptUrl
= scriptOb
.getAttribute('src');
23 if (!this.loadedScripts
[scriptUrl
])
24 this.pendingScripts
.push(['url', scriptUrl
]);
27 this.pendingScripts
.push(['code', scriptOb
]);
29 if(!this.isLoading
&& this.pendingScripts
.length
)
30 this._loadNextScript();
33 ScriptRegistry
.prototype._loadNextScript = function() {
34 var firstScript
= this.pendingScripts
[0];
36 switch (firstScript
[0]) {
38 var script
= document
.createElement( "script" );
39 script
.type
= "text/javascript";
40 script
.src
= firstScript
[1];
41 this.HEAD
.appendChild(script
);
42 this.loadedScripts
[script
.src
] = true;
43 this.isLoading
= true;
44 var thisRegistry
= this;
46 script
.onreadystatechange = function(){
47 if (script
.readyState
== 'complete' || script
.readyState
== 'loaded')
48 thisRegistry
._removeScriptAfterLoad();
51 script
.onload = function(){ thisRegistry
._removeScriptAfterLoad(); };
55 eval(firstScript
[1].text
);
59 console
.group('Embedded script error');
61 console
.info(firstScript
[1]);
65 this._removeScriptAfterLoad();
70 ScriptRegistry
.prototype._removeScriptAfterLoad = function() {
71 this.pendingScripts
.shift();
72 if(this.pendingScripts
.length
)
73 this._loadNextScript()
75 this.isLoading
= false;
78 globalScriptRegistry
= new ScriptRegistry();