twbs--bootstrap/js/dist/dom/selector-engine.js

87 lines
2.5 KiB
JavaScript
Raw Normal View History

2019-03-01 11:31:34 -05:00
/*!
2021-03-23 12:26:54 -04:00
* Bootstrap selector-engine.js v5.0.0-beta3 (https://getbootstrap.com/)
* Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
2020-06-16 14:50:01 -04:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
2019-03-01 11:31:34 -05:00
*/
(function (global, factory) {
2020-11-11 12:07:37 -05: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 11:31:34 -05:00
/**
* --------------------------------------------------------------------------
2021-03-23 12:26:54 -04:00
* Bootstrap (v5.0.0-beta3): dom/selector-engine.js
2020-06-16 14:50:01 -04:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
2019-03-01 11:31:34 -05:00
* --------------------------------------------------------------------------
*/
2020-11-11 12:07:37 -05:00
2019-03-01 11:31:34 -05:00
/**
* ------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
*/
2021-03-23 12:26:54 -04:00
const NODE_TEXT = 3;
const SelectorEngine = {
find(selector, element = document.documentElement) {
return [].concat(...Element.prototype.querySelectorAll.call(element, selector));
2019-03-01 11:31:34 -05:00
},
2021-03-23 12:26:54 -04:00
findOne(selector, element = document.documentElement) {
2020-11-11 12:07:37 -05:00
return Element.prototype.querySelector.call(element, selector);
2019-03-01 11:31:34 -05:00
},
2020-03-28 06:29:08 -04:00
2021-03-23 12:26:54 -04:00
children(element, selector) {
return [].concat(...element.children).filter(child => child.matches(selector));
2019-03-01 11:31:34 -05:00
},
2021-03-23 12:26:54 -04:00
parents(element, selector) {
const parents = [];
let ancestor = element.parentNode;
2019-03-01 11:31:34 -05:00
while (ancestor && ancestor.nodeType === Node.ELEMENT_NODE && ancestor.nodeType !== NODE_TEXT) {
if (ancestor.matches(selector)) {
2019-03-01 11:31:34 -05:00
parents.push(ancestor);
}
ancestor = ancestor.parentNode;
}
return parents;
},
2021-03-23 12:26:54 -04:00
prev(element, selector) {
let previous = element.previousElementSibling;
2020-03-28 06:29:08 -04:00
while (previous) {
if (previous.matches(selector)) {
return [previous];
}
previous = previous.previousElementSibling;
}
2019-03-01 11:31:34 -05:00
2020-03-28 06:29:08 -04:00
return [];
},
2021-03-23 12:26:54 -04:00
next(element, selector) {
let next = element.nextElementSibling;
2020-03-28 06:29:08 -04:00
while (next) {
if (next.matches(selector)) {
2020-03-28 06:29:08 -04:00
return [next];
2019-03-01 11:31:34 -05:00
}
2020-03-28 06:29:08 -04:00
next = next.nextElementSibling;
2019-03-01 11:31:34 -05:00
}
2020-03-28 06:29:08 -04:00
return [];
2019-03-01 11:31:34 -05:00
}
2021-03-23 12:26:54 -04:00
2019-03-01 11:31:34 -05:00
};
return SelectorEngine;
2019-11-08 03:11:23 -05:00
})));
//# sourceMappingURL=selector-engine.js.map