This repository was archived by the owner on Sep 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSConfigurator.class.js
More file actions
44 lines (44 loc) · 1.42 KB
/
JSConfigurator.class.js
File metadata and controls
44 lines (44 loc) · 1.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
/**
*
* Javascript configuration holder class
*
*/
var JSConfigurator = function ( defaultNamespace, defaultOptions ) {
this.namespaces = {};
this.defaultNamespace = defaultNamespace;
this.namespaces[defaultNamespace] = defaultOptions;
this.setDefaultNamespace = function (namespace) {
this.defaultNamespace = namespace;
}
this.getDefaultNamespace = function () {
return this.defaultNamespace;
}
this.put = function ( key, value, namespace ) {
if (!namespace) {
this.namespaces[this.defaultNamespace][key] = value;
}
else {
if (typeof(this.namespaces[namespace]) == 'undefined') {
this.namespaces[namespace] = {};
}
this.namespaces[namespace][key] = value;
}
}
this.putMore = function ( configArray, namespace ) {
if (!namespace) namespace = this.defaultNamespace;
if (typeof(this.namespaces[namespace]) == 'undefined') {
this.namespaces[namespace] = {};
}
for (var i in configArray ) {
this.namespaces[namespace][i] = configArray[i];
}
}
this.get = function ( key, namespace, defaultValue ) {
if (!namespace) namespace = this.defaultNamespace;
var ret = this.namespaces[namespace][key];
if (typeof(ret) == 'undefined') {
return defaultValue;
}
else return ret;
}
}