xonecas.io
142
St

startsInvasion / files

startsInvasion / libs / node_modules / qwery / qwery-mobile.js

1.9 KB
1/*!
2  * Qwery - A Blazing Fast query selector engine
3  * https://github.com/ded/qwery
4  * copyright Dustin Diaz & Jacob Thornton 2011
5  * MIT License
6  */
7
8!function (context, doc, win) {
9
10  var classOnly = /^\.([\w\-]+)$/,
11      html = doc.documentElement,
12      isAncestor = 'compareDocumentPosition' in html ?
13        function (element, container) {
14          return (container.compareDocumentPosition(element) & 16) == 16;
15        } :
16        function (element, container) {
17          container = container == doc || container == window ? html : container;
18          return container !== element && container.contains(element);
19        };
20
21  function array(ar) {
22    return [].slice.call(ar, 0);
23  }
24
25  function isNode(el) {
26    return (el && el.nodeType && (el.nodeType == 1 || el.nodeType == 9)) || el === window;
27  }
28
29  function uniq(ar) {
30    var a = [], i, j;
31    label:
32    for (i = 0; i < ar.length; i++) {
33      for (j = 0; j < a.length; j++) {
34        if (a[j] == ar[i]) {
35          continue label;
36        }
37      }
38      a[a.length] = ar[i];
39    }
40    return a;
41  }
42
43  function qwery(selector, _root, m) {
44    var root = (typeof _root == 'string') ? qwery(_root)[0] : (_root || doc);
45    if (!root || !selector) {
46      return [];
47    }
48    if (doc.getElementsByClassName && selector == 'string' && (m = selector.match(classOnly))) {
49      return array((root).getElementsByClassName(m[1]));
50    }
51    if (selector == win || selector == doc) {
52      selector = selector == doc ? doc : win;
53      return !_root ? [selector] : [null];
54    }
55    if (isNode(selector)) {
56      return !root || (isAncestor(selector, root)) ? [selector] : [];
57    }
58    return array((root).querySelectorAll(selector));
59  }
60
61
62  qwery.uniq = uniq;
63  var oldQwery = context.qwery;
64  qwery.noConflict = function () {
65    context.qwery = oldQwery;
66    return this;
67  };
68
69  context['qwery'] = qwery;
70
71}(this, document, window);