-
Notifications
You must be signed in to change notification settings - Fork 1
/
CLDynamicFileLoader.js
69 lines (69 loc) · 2.49 KB
/
CLDynamicFileLoader.js
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
66
67
68
69
CL.DynamicFileLoader = {
addLib: function(json) {
CL.DynamicFileLoader.queue[CL.DynamicFileLoader.qh] = {
type: json.location.substr(json.location.lastIndexOf(".") + 1),
src: json.location,
name: json.name,
allData: json
}
CL.DynamicFileLoader.qh++;
},
head: document.head,
qh: 0,
queue: [],
afterLoad: null,
processQueue: function(callback) {
callback = typeof(callback) == "function" ? callback: CL.DynamicFileLoader.nullFunc;
this.afterLoad = callback;
this.loadQueue();
},
loadQueue: function() {
if(CL.DynamicFileLoader.hasLibs()){
type = CL.DynamicFileLoader.queue[0].type.toLowerCase()
callback = CL.DynamicFileLoader.qh == 1 ? CL.DynamicFileLoader.afterLoad : CL.DynamicFileLoader.loadQueue;
CL.DynamicFileLoader.cases[type](callback)
CL.DynamicFileLoader.head.appendChild(script);
CL.DynamicFileLoader.queue.splice(0, 1);
CL.DynamicFileLoader.qh--;
if (!CL.DynamicFileLoader.aSyncCases[type]) callback(callback)
}
},
aSyncCases: {
css: 0,
js: 1
},
cases: {
css: function( term ){
name = CL.DynamicFileLoader.queue[0].name;
url = CL.DynamicFileLoader.queue[0].src;
media = CL.DynamicFileLoader.queue[0].allData.media;
script = document.createElement("link");
script.type = 'text/css';
script.id = name;
script.media = media;
script.rel = "stylesheet";
if(typeof(CL.Framework.runningNativeMode) == "undefined") baseURL = "";
else baseURL = ((url.indexOf("http") < 0) ? "http://" + window.location.hostname : "");
script.href = baseURL + url;
CL.DynamicFileLoader.working = 0;
return script;
},
js: function( term ){
script = document.createElement("script");
script.type = 'text/javascript';
script.onload = function() {
CL.DynamicFileLoader.head.removeChild(this);
term()
}
script.id = CL.DynamicFileLoader.queue[0].name;
if(typeof(CL.Framework.runningNativeMode) == "undefined") baseURL = "";
else baseURL = ((CL.DynamicFileLoader.queue[0].src.indexOf("http") < 0) ? "http://" + window.location.hostname : "");
script.src = baseURL + CL.DynamicFileLoader.queue[0].src;
return script;
},
},
hasLibs: function() {
return CL.DynamicFileLoader.qh;
},
nullFunc: function() {}
}