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

103 lines
3.2 KiB
JavaScript
Raw Normal View History

2019-03-01 17:31:34 +01:00
/*!
* Bootstrap selector-engine.js v4.3.1 (https://getbootstrap.com/)
2019-03-01 17:31:34 +01:00
* Copyright 2011-2019 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/
(function (global, factory) {
2019-07-12 23:56:26 +02: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 09:11:23 +01:00
}(this, (function (polyfill_js) { 'use strict';
2019-03-01 17:31:34 +01:00
/**
* --------------------------------------------------------------------------
* Bootstrap (v4.3.1): util/index.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/
var makeArray = function makeArray(nodeList) {
if (!nodeList) {
return [];
}
return [].slice.call(nodeList);
};
/**
* --------------------------------------------------------------------------
* Bootstrap (v4.3.1): dom/selector-engine.js
2019-03-01 17:31:34 +01:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/
/**
* ------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
*/
var NODE_TEXT = 3;
var SelectorEngine = {
2019-07-12 23:56:26 +02:00
matches: function matches(element, selector) {
return polyfill_js.matches.call(element, selector);
2019-03-01 17:31:34 +01:00
},
2019-07-12 23:56:26 +02:00
find: function find(selector, element) {
2019-03-01 17:31:34 +01:00
if (element === void 0) {
element = document.documentElement;
}
2019-07-12 23:56:26 +02:00
return polyfill_js.find.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;
}
2019-07-12 23:56:26 +02:00
return polyfill_js.findOne.call(element, selector);
2019-03-01 17:31:34 +01:00
},
children: function children(element, selector) {
var _this = this;
var children = makeArray(element.children);
return children.filter(function (child) {
return _this.matches(child, selector);
});
},
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;
},
2019-07-12 23:56:26 +02:00
closest: function closest(element, selector) {
return polyfill_js.closest.call(element, selector);
2019-03-01 17:31:34 +01:00
},
prev: function prev(element, selector) {
var siblings = [];
var previous = element.previousSibling;
while (previous && previous.nodeType === Node.ELEMENT_NODE && previous.nodeType !== NODE_TEXT) {
if (this.matches(previous, selector)) {
siblings.push(previous);
}
previous = previous.previousSibling;
}
return siblings;
}
};
return SelectorEngine;
2019-11-08 09:11:23 +01:00
})));
//# sourceMappingURL=selector-engine.js.map