loadScripts.js
3.5 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
* 动态加载css & js 文件
*/
(function(cdnPath) {
document.addEventListener('DOMContentLoaded', function() {
loadStyles(styleFiles);
document.removeEventListener('DOMContentLoaded', arguments.callee, false);
// callback();
}, false);
var jsFiles = [
// cdn 服务器
// jQuery and Bootstrap
/* inspiniaPath + "js/jquery/jquery-3.6.0.min.js",
inspiniaPath + "js/plugins/jquery-ui/jquery-ui.min.js",
inspiniaPath + "js/bootstrap/bootstrap.min.js",
// MetsiMenu
inspiniaPath + "js/plugins/metisMenu/jquery.metisMenu.js",
// SlimScroll
inspiniaPath + "js/plugins/slimscroll/jquery.slimscroll.min.js",
// Peace JS
inspiniaPath + "js/plugins/pace/pace.min.js",
// Custom and plugin javascript
inspiniaPath + "js/inspinia.js",
// Main Angular script
inspiniaPath + "js/angular/angular.min.js",
inspiniaPath + "js/angular/angular-route.min.js",
inspiniaPath + "js/angular/angular-sanitize.min.js",
inspiniaPath + "js/angular/angular-resource.min.js",
inspiniaPath + "js/plugins/oclazyload/dist/ocLazyLoad.min.js",
inspiniaPath + "js/ui-router/angular-ui-router.min.js",
inspiniaPath + "js/bootstrap/ui-bootstrap-tpls-1.1.2.min.js",
inspiniaPath + 'js/plugins/angular-idle/angular-idle.js',
'js/plugins/angular-local-storage/angular-local-storage.min.js',*/
// local 服务器
// Anglar App Script
"biz/common/js/app.js",
"biz/common/js/constant.js",
"biz/common/js/config.js",
"biz/common/js/services.js",
"biz/common/js/directives.js",
"biz/common/js/controllers.js",
/*"biz/common/js/notifyCtrl.js",*/
// route menu 配置
"biz/home/route.js"
];
var styleFiles = [
// cdn 服务器
// Bootstrap and Fonts
inspiniaPath + "css/bootstrap.min.css",
// Font awesome
inspiniaPath + "font-awesome/css/font-awesome.min.css",
// Main Inspinia CSS files
inspiniaPath + "css/animate.css", {
id: 'loadBefore',
url: "css/style.css"
},
inspiniaPath + 'css/plugins/angular-notify/angular-notify.min.css',
// local 服务器
{
id: 'resetBefore',
url: "css/reset.css"
},
"css/common.css"
];
function onload(dom, callback) {
dom.onload = dom.onreadystatechange = function() {
if (!this.readyState ||
'loaded' === this.readyState ||
'complete' === this.readyState) {
this.onload = this.onreadystatechange = null;
callback();
}
}
}
// 动态顺序加载js文件
function loadScript(files) {
var url = files.shift();
var script = document.createElement("script");
script.type = "text/javascript";
script.src = url;
onload(script, function() {
if (files.length > 0) {
loadScript(files);
} else {
// 启动APP
angular.element(document).ready(function() {
angular.bootstrap(document, ['inspinia']);
});
}
});
document.body.appendChild(script);
}
// 创建样式文件
function loadStyles(files) {
var url = files.shift();
var link = document.createElement("link");
link.type = "text/css";
link.rel = "stylesheet";
link.href = url.url || url;
url.id && (link.id = url.id);
onload(link, function() {
if (files.length > 0) {
loadStyles(files);
} else {
//loadScript(jsFiles);
}
});
document.getElementsByTagName("head")[0].appendChild(link);
}
})(cdnPath);