1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | (function (global, factory) {
|
25 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
26 | typeof define === 'function' && define.amd ? define(factory) :
|
27 | (global.tealight = factory());
|
28 | }(this, (function () { 'use strict';
|
29 |
|
30 | function isNode(x) {
|
31 | return typeof window.Node === 'object'
|
32 | ? x instanceof window.Node
|
33 | : x !== null &&
|
34 | typeof x === 'object' &&
|
35 | typeof x.nodeType === 'number' &&
|
36 | typeof x.nodeName === 'string'
|
37 | }
|
38 |
|
39 | function isNodeList(x) {
|
40 | var prototypeToString = Object.prototype.toString.call(x);
|
41 | var regex = /^\[object (HTMLCollection|NodeList|Object)\]$/;
|
42 |
|
43 | return typeof window.NodeList === 'object'
|
44 | ? x instanceof window.NodeList
|
45 | : x !== null &&
|
46 | typeof x === 'object' &&
|
47 | typeof x.length === 'number' &&
|
48 | regex.test(prototypeToString) &&
|
49 | (x.length === 0 || isNode(x[0]))
|
50 | }
|
51 |
|
52 | function index(target, context) {
|
53 | if ( context === void 0 ) context = document;
|
54 |
|
55 | if (target instanceof Array) { return target.filter(isNode) }
|
56 | if (isNode(target)) { return [target] }
|
57 | if (isNodeList(target)) { return Array.prototype.slice.call(target) }
|
58 | if (typeof target === 'string') {
|
59 | try {
|
60 | var query = context.querySelectorAll(target);
|
61 | return Array.prototype.slice.call(query)
|
62 | } catch (err) {
|
63 | return []
|
64 | }
|
65 | }
|
66 | return []
|
67 | }
|
68 |
|
69 | return index;
|
70 |
|
71 | })));
|