0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-13 01:08:58 +01:00
Bootstrap/js/dist/dom/polyfill.js

179 lines
4.9 KiB
JavaScript
Raw Normal View History

2019-03-01 17:31:34 +01:00
/*!
* Bootstrap polyfill.js v4.3.1 (https://getbootstrap.com/)
* 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' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = global || self, factory(global.Polyfill = {}));
2019-11-08 09:11:23 +01:00
}(this, (function (exports) { '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 MAX_UID = 1000000;
/**
* --------------------------------------------------------------------------
* Public Util Api
* --------------------------------------------------------------------------
*/
var getUID = function getUID(prefix) {
do {
prefix += ~~(Math.random() * MAX_UID); // "~~" acts like a faster Math.floor() here
} while (document.getElementById(prefix));
return prefix;
};
2019-07-12 23:56:26 +02:00
/* istanbul ignore file */
var _Element$prototype = Element.prototype;
exports.matches = _Element$prototype.matches;
exports.closest = _Element$prototype.closest;
exports.find = Element.prototype.querySelectorAll;
exports.findOne = Element.prototype.querySelector;
2019-03-01 17:31:34 +01:00
2019-07-12 23:56:26 +02:00
exports.createCustomEvent = function createCustomEvent(eventName, params) {
var cEvent = new CustomEvent(eventName, params);
return cEvent;
};
if (typeof window.CustomEvent !== 'function') {
exports.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;
};
}
2019-03-01 17:31:34 +01:00
2019-07-12 23:56:26 +02:00
var workingDefaultPrevented = function () {
var e = document.createEvent('CustomEvent');
e.initEvent('Bootstrap', true, true);
e.preventDefault();
return e.defaultPrevented;
}();
2019-03-01 17:31:34 +01:00
2019-07-12 23:56:26 +02:00
if (!workingDefaultPrevented) {
var origPreventDefault = Event.prototype.preventDefault;
2019-03-01 17:31:34 +01:00
2019-07-12 23:56:26 +02:00
Event.prototype.preventDefault = function () {
if (!this.cancelable) {
return;
2019-03-01 17:31:34 +01:00
}
2019-07-12 23:56:26 +02:00
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 = exports.createCustomEvent('Bootstrap', {
cancelable: true
});
var element = document.createElement('div');
element.addEventListener('Bootstrap', function () {
return null;
});
e.preventDefault();
element.dispatchEvent(e);
return e.defaultPrevented;
}();
2019-03-01 17:31:34 +01:00
2019-07-12 23:56:26 +02:00
if (!exports.matches) {
exports.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
}
2019-03-01 17:31:34 +01:00
2019-07-12 23:56:26 +02:00
if (!exports.closest) {
exports.closest = function closest(selector) {
var element = this;
2019-03-01 17:31:34 +01:00
2019-07-12 23:56:26 +02:00
do {
if (exports.matches.call(element, selector)) {
return element;
2019-03-01 17:31:34 +01:00
}
2019-07-12 23:56:26 +02:00
element = element.parentElement || element.parentNode;
} while (element !== null && element.nodeType === 1);
2019-03-01 17:31:34 +01:00
2019-07-12 23:56:26 +02:00
return null;
};
}
2019-03-01 17:31:34 +01:00
2019-07-12 23:56:26 +02:00
var scopeSelectorRegex = /:scope\b/;
2019-03-01 17:31:34 +01:00
2019-07-12 23:56:26 +02:00
var supportScopeQuery = function () {
var element = document.createElement('div');
2019-03-01 17:31:34 +01:00
2019-07-12 23:56:26 +02:00
try {
element.querySelectorAll(':scope *');
2019-10-08 08:39:10 +02:00
} catch (_) {
2019-07-12 23:56:26 +02: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 17:31:34 +01:00
2019-07-12 23:56:26 +02: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 17:31:34 +01:00
}
2019-07-12 23:56:26 +02:00
}
2019-03-01 17:31:34 +01:00
2019-07-12 23:56:26 +02:00
return nodeList;
};
exports.findOne = function findOne(selector) {
if (!scopeSelectorRegex.test(selector)) {
return this.querySelector(selector);
}
2019-03-01 17:31:34 +01:00
2019-07-12 23:56:26 +02:00
var matches = exports.find.call(this, selector);
if (typeof matches[0] !== 'undefined') {
return matches[0];
}
return null;
2019-03-01 17:31:34 +01:00
};
2019-07-12 23:56:26 +02:00
}
exports.defaultPreventedPreservedOnDispatch = defaultPreventedPreservedOnDispatch;
2019-03-01 17:31:34 +01:00
2019-07-12 23:56:26 +02:00
Object.defineProperty(exports, '__esModule', { value: true });
2019-03-01 17:31:34 +01:00
2019-11-08 09:11:23 +01:00
})));
2019-03-01 17:31:34 +01:00
//# sourceMappingURL=polyfill.js.map