-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetting-func-template.js
More file actions
79 lines (76 loc) · 2.42 KB
/
setting-func-template.js
File metadata and controls
79 lines (76 loc) · 2.42 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
module.exports = {
head: `
; (function () {
"use strict"
var _global;
var themeSetting = {
`,
bottom: `
change: function (key, config) {
try {
var newTheme = {};
var generate = this.generate;
if(key && typeof key === 'string') {
var currentTheme = this.theme[key] || {};
newTheme = currentTheme.config || {};
}
var newConfig = config || {};
for(var addKey in newConfig) {
newTheme[addKey] = newConfig[addKey];
}
var generateTemplateCss = this.templateCss || '';
var primaryColor = newTheme['@primary-color'];
var newTemplateCss = generateTemplateCss.split('*>').map(function (cssStr){
var newCss = cssStr;
if(newCss.includes('<**')) {
var jsonStr = newCss.split('<**')[1];
var parseRule = JSON.parse(jsonStr);
if(parseRule.insidePluginKey === 'generate' && primaryColor){
newCss = newCss.split('<**' + jsonStr).join(generate(primaryColor)[parseRule.index])
}
}
return newCss;
}).join('');
for(var themeKey in newTheme) {
newTemplateCss = newTemplateCss.replace(new RegExp(themeKey, 'g'), newTheme[themeKey]);
}
var styleDom = document.getElementById('theme-config');
if(styleDom) {
styleDom.innerHTML = newTemplateCss;
} else {
styleDom = document.createElement('style');
styleDom.id = 'theme-config';
styleDom.innerHTML = newTemplateCss;
document.body.appendChild(styleDom);
}
} catch(error) {
console.error(error);
}
},
init: function (){
var _this = this;
if(!document.getElementById('theme-config')){
var initCheck = setInterval(function (){
if(!document.getElementById('theme-config')){
if(document.body){
_this.change('default');
}
} else {
clearInterval(initCheck);
}
}, 50)
}
},
};
themeSetting.init();
_global = (function () { return this || (0, eval)('this'); }());
if (typeof module !== "undefined" && module.exports) {
module.exports = themeSetting;
} else if (typeof define === "function" && define.amd) {
define(function () { return themeSetting; });
} else {
!('themeSetting' in _global) && (_global.themeSetting = themeSetting);
}
}());
`,
};