//alert('loaded!'); var arrPath = new Array(), indexCount = 0; set_load_path = function(path){ var last = path.charAt(path.length -1); if (last != '/') path += '/'; arrPath[indexCount] = path; indexCount++; }; loadScript = function(file){ var arrCount = arrPath.length, script = null; var states = ''; for (var i=0; i < arrCount; i++){ script = document.createElement('script'); script.type = "text/javascript"; script.charset = 'UTF-8'; if(arrPath) script.src = arrPath + file; else script.src = file; // DOM é case sensitive? script.onLoad = script.onreadystatechange = function(){ if (script.readyState == 'complete') document.head.appendChild(script); states += script.readyState + '\t'; } } alert(states); };
Como podem ver, a função set_load_path assim como a set_include_path no PHP, define os caminhos onde estarão todos os scripts usados em um dado processamento, dessa forma não precisamos ficar incluindo o mesmo path trocentas vezes. A função loadScript varre o array de paths e tenta carregar o script, mas tem algo que não está saindo bem. Teste e vamos fazer isso funcionar porque será muito útil.