-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathejs_var.js
96 lines (94 loc) · 4.43 KB
/
ejs_var.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
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
/**
* build ejs 配置
* @param pathConfig
* @returns {{isPub: boolean, title: string, keywords: string, desc: string, setTitle: ejsDefaultConst.setTitle, setKeywords: ejsDefaultConst.setKeywords, setDescription: ejsDefaultConst.setDescription, beApiRootPath: (*|string), cssRootPath: *, jsRootPath: (js|string|string|string|string|string|*), imgRootPath: (string|string|string), styleFileExt: string, jsFile: string, cssFile: string, entryJsFile: string, otherFiles: string, otherCssFiles: string, appName: string, setBizJs: ejsDefaultConst.setBizJs, getBizJs: ejsDefaultConst.getBizJs, setThirdpartyJs: ejsDefaultConst.setThirdpartyJs, getThirdpartyJs: ejsDefaultConst.getThirdpartyJs, setBizCss: ejsDefaultConst.setBizCss, getBizCss: ejsDefaultConst.getBizCss, setThirdpartyCss: ejsDefaultConst.setThirdpartyCss, getThirdpartyCss: ejsDefaultConst.getThirdpartyCss}}
*/
function getEjsVar(pathConfig) {
var ejsDefaultConst = {
isPub : true,
title : "",
keywords : "",
desc : "",
setTitle : function(param) { this.title = param},
setKeywords : function(param){ this.keywords = param},
setDescription : function(param){ this.desc = param },
beApiRootPath : pathConfig.beApiRootPath , //http://\" + location.host + \"/
cssRootPath : pathConfig.css,
jsRootPath : pathConfig.js,
imgRootPath : pathConfig.img,
styleFileExt : ".css",
jsFile : '',
cssFile : '',
entryJsFile : '', // 入口模块名字。注意:在入口js文件内定义入口模块名时,必须与入口js文件名同名
otherFiles : '', //第三方js文件
otherCssFiles : '',//第三方css文件
setJs : function(param) {
if (typeof param != 'string') { //数组,入口文件放在数组最后一个位置。日后去掉seajs后可以去掉该限制
var _this = this;
param.forEach(function(p) {
_this.jsFile += '<script src="' + pathConfig.js + p + '" type="text/javascript"></script>\n';
_this.entryJsFile = p;//日后去掉seajs后可以删除
})
} else {
this.entryJsFile = param;
this.jsFile = '<script src="' + pathConfig.js + param + '" type="text/javascript"></script>';
}
},
getJs : function() {
var temp = this.jsFile;
this.jsFile = '';
return temp;
},
setThirdpartyJs : function(url) {
if (typeof url == "string") {
this.otherFiles += ' <script type="text/javascript" src="'+ url + '"></script>';
} else {
var _otherFiles = '';
url.forEach(function(e) {
_otherFiles += '\r\n <script type="text/javascript" src="'+ e + '"></script>';
});
this.otherFiles = _otherFiles;
}
},
getThirdpartyJs : function() {
var tmp = this.otherFiles;
this.otherFiles = '';
return tmp;
},
setCss : function(param) {
if (typeof param != 'string') {
var _this = this;
param.forEach(function(p) {
p = p.replace('.less', '.css')
_this.cssFile += "<link rel='stylesheet' type='text/css' href='" + pathConfig.css + p + "'/>\n";
})
} else {
param = param.replace('.less', '.css')
this.cssFile = "<link rel='stylesheet' type='text/css' href='" + pathConfig.css + param + "'/>"
}
},
getCss : function() {
var tmp = this.cssFile;
this.cssFile = '';
return tmp;
},
setThirdpartyCss : function(url) {
if (typeof url == "string") {
this.otherCssFiles += ' <link rel="stylesheet" type="text/css" href="'+ url + '" />';
} else {
var _otherFiles = '';
url.forEach(function(e) {
_otherFiles += '\r\n <link rel="stylesheet" type="text/css" href="'+ e + '" />';
});
this.otherCssFiles = _otherFiles;
}
},
getThirdpartyCss : function() {
var tmp = this.otherCssFiles;
this.otherCssFiles = '';
return tmp;
}
}
return ejsDefaultConst;
}
exports.getEjsVar = getEjsVar;