0
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-01-19 11:52:21 +01:00
Bootstrap/js/dist/dom/polyfill.js

112 lines
3.2 KiB
JavaScript
Raw Normal View History

2019-03-01 18:31:34 +02:00
/*!
2020-09-29 18:33:00 +03:00
* Bootstrap polyfill.js v5.0.0-alpha2 (https://getbootstrap.com/)
2020-03-28 12:29:08 +02:00
* Copyright 2011-2020 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
2020-06-16 21:50:01 +03:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
2019-03-01 18:31:34 +02:00
*/
(function (global, factory) {
2019-07-12 16:56:26 -05:00
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
2020-09-14 18:12:06 +03:00
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Polyfill = {}));
2019-11-08 10:11:23 +02:00
}(this, (function (exports) { 'use strict';
2019-03-01 18:31:34 +02:00
/**
* --------------------------------------------------------------------------
2020-09-29 18:33:00 +03:00
* Bootstrap (v5.0.0-alpha2): util/index.js
2020-06-16 21:50:01 +03:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
2019-03-01 18:31:34 +02:00
* --------------------------------------------------------------------------
*/
var MAX_UID = 1000000;
/**
* --------------------------------------------------------------------------
* Public Util Api
* --------------------------------------------------------------------------
*/
var getUID = function getUID(prefix) {
do {
2020-06-13 15:40:28 -07:00
prefix += Math.floor(Math.random() * MAX_UID);
2019-03-01 18:31:34 +02:00
} while (document.getElementById(prefix));
return prefix;
};
2019-07-12 16:56:26 -05:00
/* istanbul ignore file */
exports.find = Element.prototype.querySelectorAll;
2020-03-28 12:29:08 +02:00
exports.findOne = Element.prototype.querySelector; // MSEdge resets defaultPrevented flag upon dispatchEvent call if at least one listener is attached
2019-07-12 16:56:26 -05:00
var defaultPreventedPreservedOnDispatch = function () {
2020-03-28 12:29:08 +02:00
var e = new CustomEvent('Bootstrap', {
2019-07-12 16:56:26 -05:00
cancelable: true
});
var element = document.createElement('div');
element.addEventListener('Bootstrap', function () {
return null;
});
e.preventDefault();
element.dispatchEvent(e);
return e.defaultPrevented;
}();
2019-03-01 18:31:34 +02:00
2019-07-12 16:56:26 -05:00
var scopeSelectorRegex = /:scope\b/;
2019-03-01 18:31:34 +02:00
2019-07-12 16:56:26 -05:00
var supportScopeQuery = function () {
var element = document.createElement('div');
2019-03-01 18:31:34 +02:00
2019-07-12 16:56:26 -05:00
try {
element.querySelectorAll(':scope *');
2019-10-08 09:39:10 +03:00
} catch (_) {
2019-07-12 16:56:26 -05:00
return false;
}
return true;
}();
if (!supportScopeQuery) {
exports.find = function find(selector) {
if (!scopeSelectorRegex.test(selector)) {
return this.querySelectorAll(selector);
}
var hasId = Boolean(this.id);
2019-03-01 18:31:34 +02:00
2019-07-12 16:56:26 -05:00
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');
2019-03-01 18:31:34 +02:00
}
2019-07-12 16:56:26 -05:00
}
2019-03-01 18:31:34 +02:00
2019-07-12 16:56:26 -05:00
return nodeList;
};
exports.findOne = function findOne(selector) {
if (!scopeSelectorRegex.test(selector)) {
return this.querySelector(selector);
}
2019-03-01 18:31:34 +02:00
2019-07-12 16:56:26 -05:00
var matches = exports.find.call(this, selector);
if (typeof matches[0] !== 'undefined') {
return matches[0];
}
return null;
2019-03-01 18:31:34 +02:00
};
2019-07-12 16:56:26 -05:00
}
exports.defaultPreventedPreservedOnDispatch = defaultPreventedPreservedOnDispatch;
2019-03-01 18:31:34 +02:00
2019-07-12 16:56:26 -05:00
Object.defineProperty(exports, '__esModule', { value: true });
2019-03-01 18:31:34 +02:00
2019-11-08 10:11:23 +02:00
})));
2019-03-01 18:31:34 +02:00
//# sourceMappingURL=polyfill.js.map