ResourceLoader.js
1.53 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var ResourceLoader = {
'loadedType' : []
};
ResourceLoader.loadResource = function(mec_type, callbackFn){
var that = this;
if(that.isLoaded(mec_type)){
if(typeof(callbackFn) == "function"){
callbackFn.call(callbackFn);
}
}else{
$.get("/mobilemode/MECAction.jsp?action=getDesignResource&mec_type="+mec_type, function(responseText){
var resources = $.parseJSON(responseText);
for(var i = 0; i < resources.length; i++){
var r = resources[i];
var type = r["type"];
var content = r["content"];
if (type == "js") {
that.runJs(content);
} else if (type == "css"){
that.runCss(content);
}
}
that.setLoaded(mec_type);
if(typeof(callbackFn) == "function"){
callbackFn.call(callbackFn);
}
});
}
};
ResourceLoader.isLoaded = function(mec_type){
for(var i = 0; i < this.loadedType.length; i++){
if(this.loadedType[i] == mec_type){
return true;
}
}
return false;
};
ResourceLoader.setLoaded = function(mec_type){
this.loadedType.push(mec_type);
};
ResourceLoader.runCss = function (_css) {
var headEle = document.getElementsByTagName("head")[0];
var styleEle = document.createElement("style");
styleEle.setAttribute("type","text/css");
if(styleEle.styleSheet){
styleEle.styleSheet.cssText = _css;
}else{
styleEle.appendChild(document.createTextNode(_css));
}
headEle.appendChild(styleEle);
};
ResourceLoader.runJs = function (_js) {
if (window.execScript) {
window.execScript(_js)
} else {
window.eval(_js)
}
};