-
Notifications
You must be signed in to change notification settings - Fork 1
/
kick-query.js
49 lines (36 loc) · 1.17 KB
/
kick-query.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
function jDom(context, exports) {
function jDomItem(element) {
this.element = element;
}
jDomItem.prototype.addClass = function (className) {
this.element.classList.add(className);
return this;
}
//////////////////////////////////////////////////////////////////////
function jDOMCollection(jDomItems) {
this.nodes = jDomItems;
}
jDOMCollection.prototype.each = function () {};
jDOMCollection.prototype.map = function () {};
jDOMCollection.prototype.filter = function () {};
//////////////////////////////////////////////////////////////////////
function $(selectorOrNode, root) {
root = root || document;
if (typeof selectorOrNode === 'string') {
var nlist = root.querySelectorAll(selectorOrNode);
return new jDOMCollection($.nodeListToArrayOfjDomItems(nlist));
} else {
throw new Error('TODO: implement more modes');
}
}
$.is_jDomEntity = function(thing){
return thing instanceof jDomItem || thing instanceof jDOMCollection;
}
$.nodeListToArrayOfjDomItems = function(nodeList){
return Array.prototype.map.call(nodeList, function (element) {
return new jDomItem(element);
});
}
return context[exports] = $;
}
jDom(window, '$');