selector-engine.js 2.92 KB
Newer Older
XhmikosR's avatar
XhmikosR committed
1
/*!
XhmikosR's avatar
XhmikosR committed
2
  * Bootstrap selector-engine.js v5.0.0-alpha3 (https://getbootstrap.com/)
XhmikosR's avatar
XhmikosR committed
3
  * Copyright 2011-2020 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
XhmikosR's avatar
XhmikosR committed
4
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
XhmikosR's avatar
XhmikosR committed
5
6
  */
(function (global, factory) {
XhmikosR's avatar
XhmikosR committed
7
8
9
10
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  typeof define === 'function' && define.amd ? define(factory) :
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.SelectorEngine = factory());
}(this, (function () { 'use strict';
XhmikosR's avatar
XhmikosR committed
11
12
13

  /**
   * --------------------------------------------------------------------------
XhmikosR's avatar
XhmikosR committed
14
   * Bootstrap (v5.0.0-alpha3): dom/selector-engine.js
XhmikosR's avatar
XhmikosR committed
15
   * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
XhmikosR's avatar
XhmikosR committed
16
17
   * --------------------------------------------------------------------------
   */
XhmikosR's avatar
XhmikosR committed
18

XhmikosR's avatar
XhmikosR committed
19
20
21
22
23
24
25
  /**
   * ------------------------------------------------------------------------
   * Constants
   * ------------------------------------------------------------------------
   */
  var NODE_TEXT = 3;
  var SelectorEngine = {
Mark Otto's avatar
dist v5    
Mark Otto committed
26
    matches: function matches(element, selector) {
XhmikosR's avatar
XhmikosR committed
27
      return element.matches(selector);
XhmikosR's avatar
XhmikosR committed
28
    },
Mark Otto's avatar
dist v5    
Mark Otto committed
29
    find: function find(selector, element) {
XhmikosR's avatar
XhmikosR committed
30
31
      var _ref;

XhmikosR's avatar
XhmikosR committed
32
33
34
35
      if (element === void 0) {
        element = document.documentElement;
      }

XhmikosR's avatar
XhmikosR committed
36
      return (_ref = []).concat.apply(_ref, Element.prototype.querySelectorAll.call(element, selector));
XhmikosR's avatar
XhmikosR committed
37
    },
Mark Otto's avatar
dist v5    
Mark Otto committed
38
    findOne: function findOne(selector, element) {
XhmikosR's avatar
XhmikosR committed
39
40
41
42
      if (element === void 0) {
        element = document.documentElement;
      }

XhmikosR's avatar
XhmikosR committed
43
      return Element.prototype.querySelector.call(element, selector);
XhmikosR's avatar
XhmikosR committed
44
45
    },
    children: function children(element, selector) {
XhmikosR's avatar
XhmikosR committed
46
47
48
      var _ref2;

      var children = (_ref2 = []).concat.apply(_ref2, element.children);
XhmikosR's avatar
XhmikosR committed
49
50

      return children.filter(function (child) {
XhmikosR's avatar
XhmikosR committed
51
        return child.matches(selector);
XhmikosR's avatar
XhmikosR committed
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
      });
    },
    parents: function parents(element, selector) {
      var parents = [];
      var ancestor = element.parentNode;

      while (ancestor && ancestor.nodeType === Node.ELEMENT_NODE && ancestor.nodeType !== NODE_TEXT) {
        if (this.matches(ancestor, selector)) {
          parents.push(ancestor);
        }

        ancestor = ancestor.parentNode;
      }

      return parents;
    },
    prev: function prev(element, selector) {
XhmikosR's avatar
XhmikosR committed
69
70
71
72
73
74
75
76
77
      var previous = element.previousElementSibling;

      while (previous) {
        if (previous.matches(selector)) {
          return [previous];
        }

        previous = previous.previousElementSibling;
      }
XhmikosR's avatar
XhmikosR committed
78

XhmikosR's avatar
XhmikosR committed
79
80
81
82
83
84
85
86
      return [];
    },
    next: function next(element, selector) {
      var next = element.nextElementSibling;

      while (next) {
        if (this.matches(next, selector)) {
          return [next];
XhmikosR's avatar
XhmikosR committed
87
88
        }

XhmikosR's avatar
XhmikosR committed
89
        next = next.nextElementSibling;
XhmikosR's avatar
XhmikosR committed
90
91
      }

XhmikosR's avatar
XhmikosR committed
92
      return [];
XhmikosR's avatar
XhmikosR committed
93
94
95
96
97
    }
  };

  return SelectorEngine;

XhmikosR's avatar
XhmikosR committed
98
})));
99
//# sourceMappingURL=selector-engine.js.map