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

100 lines
2.9 KiB
JavaScript
Raw Normal View History

2019-03-01 11:31:34 -05:00
/*!
* Bootstrap selector-engine.js v5.0.0-alpha1 (https://getbootstrap.com/)
2020-03-28 06:29:08 -04:00
* Copyright 2011-2020 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
2019-03-01 11:31:34 -05:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/
(function (global, factory) {
2019-07-12 17:56:26 -04:00
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./polyfill.js')) :
typeof define === 'function' && define.amd ? define(['./polyfill.js'], factory) :
(global = global || self, global.SelectorEngine = factory(global.Polyfill));
2019-11-08 03:11:23 -05:00
}(this, (function (polyfill_js) { 'use strict';
2019-03-01 11:31:34 -05:00
/**
* --------------------------------------------------------------------------
* Bootstrap (v5.0.0-alpha1): dom/selector-engine.js
2019-03-01 11:31:34 -05:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/
/**
* ------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
*/
var NODE_TEXT = 3;
var SelectorEngine = {
2019-07-12 17:56:26 -04:00
matches: function matches(element, selector) {
2020-03-28 06:29:08 -04:00
return element.matches(selector);
2019-03-01 11:31:34 -05:00
},
2019-07-12 17:56:26 -04:00
find: function find(selector, element) {
2020-03-28 06:29:08 -04:00
var _ref;
2019-03-01 11:31:34 -05:00
if (element === void 0) {
element = document.documentElement;
}
2020-03-28 06:29:08 -04:00
return (_ref = []).concat.apply(_ref, polyfill_js.find.call(element, selector));
2019-03-01 11:31:34 -05:00
},
2019-07-12 17:56:26 -04:00
findOne: function findOne(selector, element) {
2019-03-01 11:31:34 -05:00
if (element === void 0) {
element = document.documentElement;
}
2019-07-12 17:56:26 -04:00
return polyfill_js.findOne.call(element, selector);
2019-03-01 11:31:34 -05:00
},
children: function children(element, selector) {
2020-03-28 06:29:08 -04:00
var _ref2;
var children = (_ref2 = []).concat.apply(_ref2, element.children);
2019-03-01 11:31:34 -05:00
return children.filter(function (child) {
2020-03-28 06:29:08 -04:00
return child.matches(selector);
2019-03-01 11:31:34 -05: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 06:29:08 -04:00
var previous = element.previousElementSibling;
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 [];
},
next: function next(element, selector) {
var next = element.nextElementSibling;
while (next) {
if (this.matches(next, selector)) {
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
}
};
return SelectorEngine;
2019-11-08 03:11:23 -05:00
})));
//# sourceMappingURL=selector-engine.js.map