0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-04 16:24:22 +01:00
Bootstrap/js/dist/dom/selector-engine.js

100 lines
2.9 KiB
JavaScript
Raw Normal View History

2019-03-01 17:31:34 +01:00
/*!
2020-11-11 18:07:37 +01:00
* Bootstrap selector-engine.js v5.0.0-alpha3 (https://getbootstrap.com/)
2020-03-28 11:29:08 +01:00
* Copyright 2011-2020 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
2020-06-16 20:50:01 +02:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
2019-03-01 17:31:34 +01:00
*/
(function (global, factory) {
2020-11-11 18:07:37 +01:00
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';
2019-03-01 17:31:34 +01:00
/**
* --------------------------------------------------------------------------
2020-11-11 18:07:37 +01:00
* Bootstrap (v5.0.0-alpha3): dom/selector-engine.js
2020-06-16 20:50:01 +02:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
2019-03-01 17:31:34 +01:00
* --------------------------------------------------------------------------
*/
2020-11-11 18:07:37 +01:00
2019-03-01 17:31:34 +01:00
/**
* ------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
*/
var NODE_TEXT = 3;
var SelectorEngine = {
2019-07-12 23:56:26 +02:00
matches: function matches(element, selector) {
2020-03-28 11:29:08 +01:00
return element.matches(selector);
2019-03-01 17:31:34 +01:00
},
2019-07-12 23:56:26 +02:00
find: function find(selector, element) {
2020-03-28 11:29:08 +01:00
var _ref;
2019-03-01 17:31:34 +01:00
if (element === void 0) {
element = document.documentElement;
}
2020-11-11 18:07:37 +01:00
return (_ref = []).concat.apply(_ref, Element.prototype.querySelectorAll.call(element, selector));
2019-03-01 17:31:34 +01:00
},
2019-07-12 23:56:26 +02:00
findOne: function findOne(selector, element) {
2019-03-01 17:31:34 +01:00
if (element === void 0) {
element = document.documentElement;
}
2020-11-11 18:07:37 +01:00
return Element.prototype.querySelector.call(element, selector);
2019-03-01 17:31:34 +01:00
},
children: function children(element, selector) {
2020-03-28 11:29:08 +01:00
var _ref2;
var children = (_ref2 = []).concat.apply(_ref2, element.children);
2019-03-01 17:31:34 +01:00
return children.filter(function (child) {
2020-03-28 11:29:08 +01:00
return child.matches(selector);
2019-03-01 17:31:34 +01:00
});
},
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) {
2020-03-28 11:29:08 +01:00
var previous = element.previousElementSibling;
while (previous) {
if (previous.matches(selector)) {
return [previous];
}
previous = previous.previousElementSibling;
}
2019-03-01 17:31:34 +01:00
2020-03-28 11:29:08 +01:00
return [];
},
next: function next(element, selector) {
var next = element.nextElementSibling;
while (next) {
if (this.matches(next, selector)) {
return [next];
2019-03-01 17:31:34 +01:00
}
2020-03-28 11:29:08 +01:00
next = next.nextElementSibling;
2019-03-01 17:31:34 +01:00
}
2020-03-28 11:29:08 +01:00
return [];
2019-03-01 17:31:34 +01:00
}
};
return SelectorEngine;
2019-11-08 09:11:23 +01:00
})));
//# sourceMappingURL=selector-engine.js.map