Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Jan 19, 2022. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathdom.js
More file actions
Latest commit
105 lines (96 loc) · 3.1 KB
/
Copy pathdom.js
File metadata and controls
105 lines (96 loc) · 3.1 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
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
vardom=(function(win,doc,undefined){
functiondom(sel){
if(sel===window)returnwindow;
varret=sel.nodeType ? [sel] : arr(doc.querySelectorAll(sel));
ret.on=function(type,handler){
ret.forEach(function(el){
on(el,type,handler)
});
returnret;
};
ret.delegate=function(type,sel,handler){
ret.forEach(function(delegateEl){
on(delegateEl,type,function(e,t){
varmatches=delegateEl.querySelectorAll(sel);
if(!matches.length)return;
for(varel=t;el.parentNode&&el!=delegateEl;el=el.parentNode){
for(vari=0;i<matches.length;i++){
if(matches[i]==el){
handler.call(el,e);
return;
}
}
}
});
});
returnret;
};
ret.css=function(o){
if(typeofo=='object'){
for(variino){
if(!o.hasOwnProperty(i))continue;
ret.forEach(function(el){
el.style.setProperty(i,o[i]);
});
}
returnret;
}
returnwin.getComputedStyle(ret[0]).getPropertyValue(o);
};
ret.attr=function(o){
if(typeofo=='object'){
for(variino){
if(!o.hasOwnProperty(i))continue;
ret.forEach(function(el){
el.setAttribute(i,o[i]);
});
}
returnret;
}
returnret[0].getAttribute(o);
};
ret.prop=function(o){
ret.forEach(function(el){
extend(el,o);
});
returnret;
};
ret.append=function(el){
ret[0].appendChild(el.length ? el[0] : el);
returnret;
};
ret.empty=function(){
ret.forEach(empty);
returnret;
};
ret.text=function(s){
ret[0].appendChild(doc.createTextNode(s));
returnret;
};
returnret;
};
vararr=dom.arr=function(a,i){
returnArray.prototype.slice.call(a,i||0);
};
varextend=dom.extend=functionextend(d,s){
for(pins){
if(s.hasOwnProperty(p)){
d[p]=s[p];
}
}
};
varon=dom.on=functionon(obj,type,handler){
obj.addEventListener(type,function(e){
handler(e,e.target);
},false);
};
varempty=dom.empty=functionempty(el){
while(el.childNodes.length){
el.removeChild(el.firstChild);
}
};
dom.tag=functiontag(name){
returndom(doc.createElement(name));
};
returndom;
})(window,document);