-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatterns.js
64 lines (58 loc) · 1.2 KB
/
patterns.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
/**
* Created by bardiles on 14.05.14.
*/
(function(){
this.MYLIB = {};
this.MYLIB.namespace = function(nameSpaceString){
var parts = nameSpaceString.split('.'),
parent = MYLIB,
i;
if (parts[0] === 'MYLIB'){
parts = parts.slice(1);
}
for (i = 0; i < parts.length; i += 1) {
if (typeof parent[parts[i]] == 'undefined') {
parent[parts[i]] = {};
}
parent = parent[parts[i]];
}
return parent;
};
this.MYLIB.getRandomColor = function(){
var rgb = [];
for (var i = 0; i < 3; i++) {
rgb[i] = Math.round(255 * Math.random());
}
return 'rgb(' + rgb.join(',') + ')';
};
this.MYLIB.constans = (function () {
var constants = {},
ownProp = Object.prototype.hasOwnProperty,
allowed = {
string: 1,
number: 1,
boolean: 1
};
return {
define: function (name, value) {
if (this.defined(name)) {
return false;
}
if (!ownProp.call(allowed, typeof value)) {
return false;
}
constants[name] = value;
return true;
},
defined: function (name) {
return ownProp.call(constants, name);
},
get: function (name) {
if (this.defined(name)) {
return constants[name];
}
return null;
}
};
}());
})();