-
Notifications
You must be signed in to change notification settings - Fork 0
/
delphic.inject.js
66 lines (50 loc) · 1.48 KB
/
delphic.inject.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
/* ===================================================
* Delphic.inject.js
* Delphic Digital
* ===================================================
* ========================================================== */
;(function (DELPHIC, $LAB) {
$LAB.setGlobalDefaults({Debug:false, AlwaysPreserveOrder:true});
DELPHIC.inject = function(f,c){
var queue = [], $chain = $LAB;
if (f instanceof Array) {
for (var i=0, len=f.length; i<len; i++) {
queue.push(f[i]);
}
}else if (typeof f == "string") {
queue = DELPHIC.LABconfig.shortcuts[f];
}
for (var i=0, len=queue.length; i<len; i++) {
var which = queue[i];
var path = DELPHIC.LABconfig.paths[which] || which;
var type = path.split('.').pop();
//var type = (path.indexOf('.js')!="-1") ? 'js' : 'css';
if(!DEBUG){ path = path.replace(/(.*)\/(.*)(\.js|.css$)/i, '$1/$2.min$3?v=')+DELPHIC.ver};
switch(type) {
case 'js':
injectJS(path);
break;
case 'css':
injectCSS(path);
break;
default:
return;
}
}
if (typeof c === "function"){
$chain = $chain.wait(c);
}
function injectJS(filename){
$chain = $chain.script(filename);
}
function injectCSS(filename) {
var fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet")
fileref.setAttribute("type", "text/css")
fileref.setAttribute("href", filename)
if (typeof fileref!="undefined"){
document.getElementsByTagName("head")[0].appendChild(fileref)
}
}
}
} (DELPHIC = window.DELPHIC || {}, $LAB));