mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-16 18:44:01 +02:00
dist v5
This commit is contained in:
179
js/dist/dom/selector-engine.js
vendored
179
js/dist/dom/selector-engine.js
vendored
@@ -4,10 +4,10 @@
|
||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
||||
*/
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
(global = global || self, global.SelectorEngine = factory());
|
||||
}(this, function () { 'use strict';
|
||||
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));
|
||||
}(this, function (polyfill_js) { 'use strict';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
@@ -15,24 +15,8 @@
|
||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
var MAX_UID = 1000000;
|
||||
var _window = window,
|
||||
jQuery = _window.jQuery; // Shoutout AngusCroll (https://goo.gl/pxwQGp)
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Public Util Api
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
var getUID = function getUID(prefix) {
|
||||
do {
|
||||
// eslint-disable-next-line no-bitwise
|
||||
prefix += ~~(Math.random() * MAX_UID); // "~~" acts like a faster Math.floor() here
|
||||
} while (document.getElementById(prefix));
|
||||
|
||||
return prefix;
|
||||
};
|
||||
|
||||
var makeArray = function makeArray(nodeList) {
|
||||
if (!nodeList) {
|
||||
@@ -42,145 +26,6 @@
|
||||
return [].slice.call(nodeList);
|
||||
};
|
||||
|
||||
/* istanbul ignore file */
|
||||
var _Element$prototype = Element.prototype,
|
||||
matches = _Element$prototype.matches,
|
||||
closest = _Element$prototype.closest;
|
||||
var find = Element.prototype.querySelectorAll;
|
||||
var findOne = Element.prototype.querySelector;
|
||||
|
||||
var createCustomEvent = function createCustomEvent(eventName, params) {
|
||||
var cEvent = new CustomEvent(eventName, params);
|
||||
return cEvent;
|
||||
};
|
||||
|
||||
if (typeof window.CustomEvent !== 'function') {
|
||||
createCustomEvent = function createCustomEvent(eventName, params) {
|
||||
params = params || {
|
||||
bubbles: false,
|
||||
cancelable: false,
|
||||
detail: null
|
||||
};
|
||||
var evt = document.createEvent('CustomEvent');
|
||||
evt.initCustomEvent(eventName, params.bubbles, params.cancelable, params.detail);
|
||||
return evt;
|
||||
};
|
||||
}
|
||||
|
||||
var workingDefaultPrevented = function () {
|
||||
var e = document.createEvent('CustomEvent');
|
||||
e.initEvent('Bootstrap', true, true);
|
||||
e.preventDefault();
|
||||
return e.defaultPrevented;
|
||||
}();
|
||||
|
||||
if (!workingDefaultPrevented) {
|
||||
var origPreventDefault = Event.prototype.preventDefault;
|
||||
|
||||
Event.prototype.preventDefault = function () {
|
||||
if (!this.cancelable) {
|
||||
return;
|
||||
}
|
||||
|
||||
origPreventDefault.call(this);
|
||||
Object.defineProperty(this, 'defaultPrevented', {
|
||||
get: function get() {
|
||||
return true;
|
||||
},
|
||||
configurable: true
|
||||
});
|
||||
};
|
||||
} // MSEdge resets defaultPrevented flag upon dispatchEvent call if at least one listener is attached
|
||||
|
||||
|
||||
var defaultPreventedPreservedOnDispatch = function () {
|
||||
var e = createCustomEvent('Bootstrap', {
|
||||
cancelable: true
|
||||
});
|
||||
var element = document.createElement('div');
|
||||
element.addEventListener('Bootstrap', function () {
|
||||
return null;
|
||||
});
|
||||
e.preventDefault();
|
||||
element.dispatchEvent(e);
|
||||
return e.defaultPrevented;
|
||||
}();
|
||||
|
||||
if (!matches) {
|
||||
matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
|
||||
}
|
||||
|
||||
if (!closest) {
|
||||
closest = function closest(selector) {
|
||||
var element = this;
|
||||
|
||||
do {
|
||||
if (matches.call(element, selector)) {
|
||||
return element;
|
||||
}
|
||||
|
||||
element = element.parentElement || element.parentNode;
|
||||
} while (element !== null && element.nodeType === 1);
|
||||
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
var scopeSelectorRegex = /:scope\b/;
|
||||
|
||||
var supportScopeQuery = function () {
|
||||
var element = document.createElement('div');
|
||||
|
||||
try {
|
||||
element.querySelectorAll(':scope *');
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}();
|
||||
|
||||
if (!supportScopeQuery) {
|
||||
find = function find(selector) {
|
||||
if (!scopeSelectorRegex.test(selector)) {
|
||||
return this.querySelectorAll(selector);
|
||||
}
|
||||
|
||||
var hasId = Boolean(this.id);
|
||||
|
||||
if (!hasId) {
|
||||
this.id = getUID('scope');
|
||||
}
|
||||
|
||||
var nodeList = null;
|
||||
|
||||
try {
|
||||
selector = selector.replace(scopeSelectorRegex, "#" + this.id);
|
||||
nodeList = this.querySelectorAll(selector);
|
||||
} finally {
|
||||
if (!hasId) {
|
||||
this.removeAttribute('id');
|
||||
}
|
||||
}
|
||||
|
||||
return nodeList;
|
||||
};
|
||||
|
||||
findOne = function findOne(selector) {
|
||||
if (!scopeSelectorRegex.test(selector)) {
|
||||
return this.querySelector(selector);
|
||||
}
|
||||
|
||||
var matches = find.call(this, selector);
|
||||
|
||||
if (typeof matches[0] !== 'undefined') {
|
||||
return matches[0];
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Bootstrap (v4.3.1): dom/selector-engine.js
|
||||
@@ -195,10 +40,10 @@
|
||||
|
||||
var NODE_TEXT = 3;
|
||||
var SelectorEngine = {
|
||||
matches: function matches$1(element, selector) {
|
||||
return matches.call(element, selector);
|
||||
matches: function matches(element, selector) {
|
||||
return polyfill_js.matches.call(element, selector);
|
||||
},
|
||||
find: function find$1(selector, element) {
|
||||
find: function find(selector, element) {
|
||||
if (element === void 0) {
|
||||
element = document.documentElement;
|
||||
}
|
||||
@@ -207,9 +52,9 @@
|
||||
return null;
|
||||
}
|
||||
|
||||
return find.call(element, selector);
|
||||
return polyfill_js.find.call(element, selector);
|
||||
},
|
||||
findOne: function findOne$1(selector, element) {
|
||||
findOne: function findOne(selector, element) {
|
||||
if (element === void 0) {
|
||||
element = document.documentElement;
|
||||
}
|
||||
@@ -218,7 +63,7 @@
|
||||
return null;
|
||||
}
|
||||
|
||||
return findOne.call(element, selector);
|
||||
return polyfill_js.findOne.call(element, selector);
|
||||
},
|
||||
children: function children(element, selector) {
|
||||
var _this = this;
|
||||
@@ -250,12 +95,12 @@
|
||||
|
||||
return parents;
|
||||
},
|
||||
closest: function closest$1(element, selector) {
|
||||
closest: function closest(element, selector) {
|
||||
if (typeof selector !== 'string') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return closest.call(element, selector);
|
||||
return polyfill_js.closest.call(element, selector);
|
||||
},
|
||||
prev: function prev(element, selector) {
|
||||
if (typeof selector !== 'string') {
|
||||
|
Reference in New Issue
Block a user