Newer
Older
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
var proto,
TinyDOMFunction,
tinyDOM;
/*
* Polyfill from https://gist.github.com/elijahmanor/6452535
*/
if (Element && !Element.prototype.matches) {
proto = Element.prototype;
proto.matches = proto.matchesSelector ||
proto.mozMatchesSelector || proto.msMatchesSelector ||
proto.oMatchesSelector || proto.webkitMatchesSelector;
}
/*
* End Polyfill
*/
TinyDOMFunction = function (selector) {
var elements, i, e;
if (!(this instanceof TinyDOMFunction)) {
return new TinyDOMFunction(selector);
}
if (selector === null || typeof (selector) === 'undefined') {
this.length = 0;
} else if (typeof (selector) === 'string') {
elements = document.querySelectorAll(selector);
this.length = elements.length;
for (i = 0; i < elements.length; i++) {
e = elements.item(i);
this[i] = e;
}
} else if (selector.length) {
for (i = 0; i < selector.length; i++) {
e = selector[i];
this[i] = e;
}
} else {
this[0] = selector;
this.length = 1;
}
this.apiversion = "1";