forked from fex-team/kityminder-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.service.js
65 lines (51 loc) · 1.5 KB
/
config.service.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
angular.module('kityminderEditor')
.provider('config', function() {
this.config = {
// 右侧面板最小宽度
ctrlPanelMin: 250,
// 右侧面板宽度
ctrlPanelWidth: parseInt(window.localStorage.__dev_minder_ctrlPanelWidth) || 250,
// 分割线宽度
dividerWidth: 3,
// 默认语言
lang: 'zh_CN',
// 放大缩小比例
zoom: [10, 20, 30, 50, 80, 100, 120, 150, 200],
};
this.set = function(key, value) {
var supported = Object.keys(this.config);
var configObj = {};
// 支持全配置
if (typeof key === 'object') {
configObj = key;
}
else {
configObj[key] = value;
}
for (var i in configObj) {
if (configObj.hasOwnProperty(i) && supported.indexOf(i) !== -1) {
this.config[i] = configObj[i];
}
else {
console.error('Unsupported config key: ', key, ', please choose in :', supported.join(', '));
return false;
}
}
return true;
};
this.$get = function () {
var me = this;
return {
get: function (key) {
if (arguments.length === 0) {
return me.config;
}
if (me.config.hasOwnProperty(key)) {
return me.config[key];
}
console.warn('Missing config key pair for : ', key);
return '';
}
};
}
});