1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| loadjs = function(url, onComplete) {
var h = document.getElementsByTagName('head').item(0);
var s = document.createElement('script');
s.src = url+".js";
s.type = "text/javascript";
h.appendChild(s);
/* IE */
s.onreadystatechange = function () {
if (s.readyState == 'loaded'){
if (typeof onComplete == "function"){
onComplete();
s = null;
}
}
}
/* FF */
/* attention, sous FF2, si le fichier a charger existe mais qu'il est vide,
l'evenement onload n'est pas lancé, ce qui peut conduire à un blocage */
s.onload = function(){
if (typeof onComplete == "function"){
onComplete();
s = null;
}
}
};
this.do = function(type) {
loadjs(type, function(_type){
return function(){
switch(_type) {
case "win":
var test = new win;
case "cool":
var test = new prob;
}
}(type)
});
} |
Partager