-
Notifications
You must be signed in to change notification settings - Fork 0
/
elt.js
64 lines (64 loc) · 1.39 KB
/
elt.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
function elt(self) {
if (typeof self == 'string') { // TODO new instead
self = document.createElement(self)
}
return {
self: self,
attributes: {
'#': '', // ID
'.': [] // Class
},
has: function(x) {
// Has class x
if (x[0] == '.') {
return self.classList.has(x.substr(1))
}
// Has attribute x
else {
return !!self.attributes[x]
}
// TODO
// Has parent
// Has child
// Has sibling
},
add: function(x) {
// Add DOM element x
if (x.self && x.self.blur) {
return self.appendChild(x.self)
}
// Add object x
else if (x.constructor == Object) {
for (var i in x) {
if (i == '.') {
this.attributes[i].push(x[i])
self.classList.add(x[i])
}
else {
this.attributes[i] = x[i]
self.setAttribute(i, x[i])
}
}
}
// Add HTML x
else {
self.innerHTML += x
}
return this
},
remove: function(x) {
// Remove class x
if (x[0] == '.') {
self.classList.remove(x.substr(1))
var index = this.attributes['.'].indexOf(x.substr(1))
if (index > -1) {
this.attributes['.'].splice(index, 1)
}
}
// Remove attribute x
else {
self.removeAttribute(x)
}
}
}
}