diff options
Diffstat (limited to 'js/dist/dom/polyfill.js')
-rw-r--r-- | js/dist/dom/polyfill.js | 196 |
1 files changed, 125 insertions, 71 deletions
diff --git a/js/dist/dom/polyfill.js b/js/dist/dom/polyfill.js index ac86ba6ee8..91b4ce3430 100644 --- a/js/dist/dom/polyfill.js +++ b/js/dist/dom/polyfill.js @@ -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.Polyfill = factory()); -}(this, function () { 'use strict'; + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : + typeof define === 'function' && define.amd ? define(['exports'], factory) : + (global = global || self, factory(global.Polyfill = {})); +}(this, function (exports) { 'use strict'; /** * -------------------------------------------------------------------------- @@ -34,94 +34,148 @@ return prefix; }; - /** - * -------------------------------------------------------------------------- - * Bootstrap (v4.3.1): dom/polyfill.js - * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) - * -------------------------------------------------------------------------- - */ - /* istanbul ignore next */ + /* 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; - var Polyfill = function () { - // MSEdge resets defaultPrevented flag upon dispatchEvent call if at least one listener is attached - var defaultPreventedPreservedOnDispatch = function () { - var e = new CustomEvent('Bootstrap', { - cancelable: true - }); - var element = document.createElement('div'); - element.addEventListener('Bootstrap', function () { - return null; - }); - e.preventDefault(); - element.dispatchEvent(e); - return e.defaultPrevented; - }(); + 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; + }; + } - var find = Element.prototype.querySelectorAll; - var findOne = Element.prototype.querySelector; - var scopeSelectorRegex = /:scope\b/; + var workingDefaultPrevented = function () { + var e = document.createEvent('CustomEvent'); + e.initEvent('Bootstrap', true, true); + e.preventDefault(); + return e.defaultPrevented; + }(); - var supportScopeQuery = function () { - var element = document.createElement('div'); + if (!workingDefaultPrevented) { + var origPreventDefault = Event.prototype.preventDefault; - try { - element.querySelectorAll(':scope *'); - } catch (error) { - return false; + Event.prototype.preventDefault = function () { + if (!this.cancelable) { + return; } - return true; - }(); + 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; + }(); - if (!supportScopeQuery) { - find = function find(selector) { - if (!scopeSelectorRegex.test(selector)) { - return this.querySelectorAll(selector); - } + if (!exports.matches) { + exports.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector; + } - var hasId = Boolean(this.id); + if (!exports.closest) { + exports.closest = function closest(selector) { + var element = this; - if (!hasId) { - this.id = getUID('scope'); + do { + if (exports.matches.call(element, selector)) { + return element; } - var nodeList = null; + element = element.parentElement || element.parentNode; + } while (element !== null && element.nodeType === 1); - try { - selector = selector.replace(scopeSelectorRegex, "#" + this.id); - nodeList = this.querySelectorAll(selector); - } finally { - if (!hasId) { - this.removeAttribute('id'); - } - } + return null; + }; + } - return nodeList; - }; + var scopeSelectorRegex = /:scope\b/; - findOne = function findOne(selector) { - if (!scopeSelectorRegex.test(selector)) { - return this.querySelector(selector); - } + var supportScopeQuery = function () { + var element = document.createElement('div'); - var matches = find.call(this, selector); + try { + element.querySelectorAll(':scope *'); + } catch (error) { + return false; + } + + return true; + }(); + + if (!supportScopeQuery) { + exports.find = function find(selector) { + if (!scopeSelectorRegex.test(selector)) { + return this.querySelectorAll(selector); + } + + var hasId = Boolean(this.id); - if (typeof matches[0] !== 'undefined') { - return matches[0]; + 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 null; - }; - } + return nodeList; + }; + + exports.findOne = function findOne(selector) { + if (!scopeSelectorRegex.test(selector)) { + return this.querySelector(selector); + } - return { - defaultPreventedPreservedOnDispatch: defaultPreventedPreservedOnDispatch, - find: find, - findOne: findOne + var matches = exports.find.call(this, selector); + + if (typeof matches[0] !== 'undefined') { + return matches[0]; + } + + return null; }; - }(); + } + + exports.defaultPreventedPreservedOnDispatch = defaultPreventedPreservedOnDispatch; - return Polyfill; + Object.defineProperty(exports, '__esModule', { value: true }); })); //# sourceMappingURL=polyfill.js.map |