-
Notifications
You must be signed in to change notification settings - Fork 2
/
_env.js
130 lines (100 loc) · 3.03 KB
/
_env.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Conkitty common functions.
(function($C, window) {
$C.tpl = {};
$C._tpl = {};
var Node = window.Node,
$ConkittyEventHandlers = [],
whitespace = /[\x20\t\r\n\f]/;
$C.on = function on(callback) {
$ConkittyEventHandlers.push(callback);
};
$C.off = function off(callback) {
if (callback) {
var i = $ConkittyEventHandlers.length - 1;
while (i >= 0) {
if ($ConkittyEventHandlers[i] === callback) {
$ConkittyEventHandlers.splice(i, 1);
} else {
i--;
}
}
} else {
$ConkittyEventHandlers = [];
}
};
$C.define('trigger', function (val, key, obj, args) {
var i,
arg;
for (i = 0; i < args.length; i++) {
if (typeof ((arg = args[i])) === 'function') {
args[i] = arg.call(this, val, key, obj);
}
}
for (i = 0; i < $ConkittyEventHandlers.length; i++) {
$ConkittyEventHandlers[i].apply(this, args);
}
});
function EnvClass(parent, payload) {
this.p = parent;
this.d = payload;
}
EnvClass.prototype.l = function getPayload(parent) {
var self = this,
ret;
if (self.d) {
// Trying to get cached payload.
if (!((ret = self._p))) {
ret = self._p = self.d();
}
if (!parent) {
return ret.firstChild ? ret : undefined;
}
ret && parent.appendChild(ret);
delete self._p;
}
};
$C._$args = [
$C,
EnvClass,
function getEnv(obj) {
return obj instanceof EnvClass ? obj : new EnvClass(obj instanceof Node ? obj : undefined);
},
function joinClasses() {
var i, ret = [], arg;
for (i = 0; i < arguments.length; i++) {
if ((arg = arguments[i])) {
ret.push(arg);
}
}
return ret.length ? ret.join(' ') : undefined;
},
function getModClass(name, val) {
if (val) {
return val === true ? name : name + '_' + val;
}
},
function getChangedClass(node, classes, remove) {
var cur = (node.getAttribute('class') || '').split(whitespace),
change = (classes || '').split(whitespace),
i,
curObj = {};
for (i = 0; i < cur.length; i++) {
curObj[cur[i]] = true;
}
for (i = 0; i < change.length; i++) {
if (remove) {
delete curObj[change[i]];
} else {
curObj[change[i]] = true;
}
}
cur = [];
for (i in curObj) {
cur.push(i);
}
return cur.join(' ');
},
window,
Node
];
})($C, window);