1
0
Fork 0
mirror of https://github.com/twbs/bootstrap.git synced 2022-11-09 12:25:43 -05:00
twbs--bootstrap/js/dist/dom/polyfill.js.map
2019-08-27 16:03:21 +03:00

1 line
No EOL
13 KiB
Text

{"version":3,"file":"polyfill.js","sources":["../../src/util/index.js","../../src/dom/polyfill.js"],"sourcesContent":["/**\n * --------------------------------------------------------------------------\n * Bootstrap (v4.3.1): util/index.js\n * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)\n * --------------------------------------------------------------------------\n */\n\nconst MAX_UID = 1000000\nconst MILLISECONDS_MULTIPLIER = 1000\nconst TRANSITION_END = 'transitionend'\n\n// Shoutout AngusCroll (https://goo.gl/pxwQGp)\nconst toType = obj => ({}.toString.call(obj).match(/\\s([a-z]+)/i)[1].toLowerCase())\n\n/**\n * --------------------------------------------------------------------------\n * Public Util Api\n * --------------------------------------------------------------------------\n */\n\nconst getUID = prefix => {\n do {\n // eslint-disable-next-line no-bitwise\n prefix += ~~(Math.random() * MAX_UID) // \"~~\" acts like a faster Math.floor() here\n } while (document.getElementById(prefix))\n\n return prefix\n}\n\nconst getSelector = element => {\n let selector = element.getAttribute('data-target')\n\n if (!selector || selector === '#') {\n const hrefAttr = element.getAttribute('href')\n\n selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : null\n }\n\n return selector\n}\n\nconst getSelectorFromElement = element => {\n const selector = getSelector(element)\n\n if (selector) {\n return document.querySelector(selector) ? selector : null\n }\n\n return null\n}\n\nconst getElementFromSelector = element => {\n const selector = getSelector(element)\n\n return selector ? document.querySelector(selector) : null\n}\n\nconst getTransitionDurationFromElement = element => {\n if (!element) {\n return 0\n }\n\n // Get transition-duration of the element\n let {\n transitionDuration,\n transitionDelay\n } = window.getComputedStyle(element)\n\n const floatTransitionDuration = parseFloat(transitionDuration)\n const floatTransitionDelay = parseFloat(transitionDelay)\n\n // Return 0 if element or transition duration is not found\n if (!floatTransitionDuration && !floatTransitionDelay) {\n return 0\n }\n\n // If multiple durations are defined, take the first\n transitionDuration = transitionDuration.split(',')[0]\n transitionDelay = transitionDelay.split(',')[0]\n\n return (parseFloat(transitionDuration) + parseFloat(transitionDelay)) * MILLISECONDS_MULTIPLIER\n}\n\nconst triggerTransitionEnd = element => {\n const evt = document.createEvent('HTMLEvents')\n\n evt.initEvent(TRANSITION_END, true, true)\n element.dispatchEvent(evt)\n}\n\nconst isElement = obj => (obj[0] || obj).nodeType\n\nconst emulateTransitionEnd = (element, duration) => {\n let called = false\n const durationPadding = 5\n const emulatedDuration = duration + durationPadding\n function listener() {\n called = true\n element.removeEventListener(TRANSITION_END, listener)\n }\n\n element.addEventListener(TRANSITION_END, listener)\n setTimeout(() => {\n if (!called) {\n triggerTransitionEnd(element)\n }\n }, emulatedDuration)\n}\n\nconst typeCheckConfig = (componentName, config, configTypes) => {\n Object.keys(configTypes)\n .forEach(property => {\n const expectedTypes = configTypes[property]\n const value = config[property]\n const valueType = value && isElement(value) ?\n 'element' :\n toType(value)\n\n if (!new RegExp(expectedTypes).test(valueType)) {\n throw new Error(\n `${componentName.toUpperCase()}: ` +\n `Option \"${property}\" provided type \"${valueType}\" ` +\n `but expected type \"${expectedTypes}\".`)\n }\n })\n}\n\nconst makeArray = nodeList => {\n if (!nodeList) {\n return []\n }\n\n return [].slice.call(nodeList)\n}\n\nconst isVisible = element => {\n if (!element) {\n return false\n }\n\n if (element.style && element.parentNode && element.parentNode.style) {\n return element.style.display !== 'none' &&\n element.parentNode.style.display !== 'none' &&\n element.style.visibility !== 'hidden'\n }\n\n return false\n}\n\nconst findShadowRoot = element => {\n if (!document.documentElement.attachShadow) {\n return null\n }\n\n // Can find the shadow root otherwise it'll return the document\n if (typeof element.getRootNode === 'function') {\n const root = element.getRootNode()\n return root instanceof ShadowRoot ? root : null\n }\n\n if (element instanceof ShadowRoot) {\n return element\n }\n\n // when we don't find a shadow root\n if (!element.parentNode) {\n return null\n }\n\n return findShadowRoot(element.parentNode)\n}\n\n// eslint-disable-next-line no-empty-function\nconst noop = () => function () {}\n\nconst reflow = element => element.offsetHeight\n\nconst getjQuery = () => {\n const { jQuery } = window\n\n if (jQuery && !document.body.hasAttribute('data-no-jquery')) {\n return jQuery\n }\n\n return null\n}\n\nexport {\n getjQuery,\n TRANSITION_END,\n getUID,\n getSelectorFromElement,\n getElementFromSelector,\n getTransitionDurationFromElement,\n triggerTransitionEnd,\n isElement,\n emulateTransitionEnd,\n typeCheckConfig,\n makeArray,\n isVisible,\n findShadowRoot,\n noop,\n reflow\n}\n","/* istanbul ignore file */\n\n/**\n * --------------------------------------------------------------------------\n * Bootstrap (v4.3.1): dom/polyfill.js\n * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)\n * --------------------------------------------------------------------------\n */\n\nimport { getUID } from '../util/index'\n\nlet { matches, closest } = Element.prototype\nlet find = Element.prototype.querySelectorAll\nlet findOne = Element.prototype.querySelector\nlet createCustomEvent = (eventName, params) => {\n const cEvent = new CustomEvent(eventName, params)\n\n return cEvent\n}\n\nif (typeof window.CustomEvent !== 'function') {\n createCustomEvent = (eventName, params) => {\n params = params || { bubbles: false, cancelable: false, detail: null }\n\n const evt = document.createEvent('CustomEvent')\n\n evt.initCustomEvent(eventName, params.bubbles, params.cancelable, params.detail)\n return evt\n }\n}\n\nconst workingDefaultPrevented = (() => {\n const e = document.createEvent('CustomEvent')\n\n e.initEvent('Bootstrap', true, true)\n e.preventDefault()\n return e.defaultPrevented\n})()\n\nif (!workingDefaultPrevented) {\n const origPreventDefault = Event.prototype.preventDefault\n\n Event.prototype.preventDefault = function () {\n if (!this.cancelable) {\n return\n }\n\n origPreventDefault.call(this)\n Object.defineProperty(this, 'defaultPrevented', {\n get() {\n return true\n },\n configurable: true\n })\n }\n}\n\n// MSEdge resets defaultPrevented flag upon dispatchEvent call if at least one listener is attached\nconst defaultPreventedPreservedOnDispatch = (() => {\n const e = createCustomEvent('Bootstrap', {\n cancelable: true\n })\n\n const element = document.createElement('div')\n element.addEventListener('Bootstrap', () => null)\n\n e.preventDefault()\n element.dispatchEvent(e)\n return e.defaultPrevented\n})()\n\nif (!matches) {\n matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector\n}\n\nif (!closest) {\n closest = function (selector) {\n let element = this\n\n do {\n if (matches.call(element, selector)) {\n return element\n }\n\n element = element.parentElement || element.parentNode\n } while (element !== null && element.nodeType === 1)\n\n return null\n }\n}\n\nconst scopeSelectorRegex = /:scope\\b/\nconst supportScopeQuery = (() => {\n const element = document.createElement('div')\n\n try {\n element.querySelectorAll(':scope *')\n } catch (error) {\n return false\n }\n\n return true\n})()\n\nif (!supportScopeQuery) {\n find = function (selector) {\n if (!scopeSelectorRegex.test(selector)) {\n return this.querySelectorAll(selector)\n }\n\n const hasId = Boolean(this.id)\n\n if (!hasId) {\n this.id = getUID('scope')\n }\n\n let nodeList = null\n try {\n selector = selector.replace(scopeSelectorRegex, `#${this.id}`)\n nodeList = this.querySelectorAll(selector)\n } finally {\n if (!hasId) {\n this.removeAttribute('id')\n }\n }\n\n return nodeList\n }\n\n findOne = function (selector) {\n if (!scopeSelectorRegex.test(selector)) {\n return this.querySelector(selector)\n }\n\n const matches = find.call(this, selector)\n\n if (typeof matches[0] !== 'undefined') {\n return matches[0]\n }\n\n return null\n }\n}\n\nexport {\n createCustomEvent,\n find,\n findOne,\n matches,\n closest,\n defaultPreventedPreservedOnDispatch\n}\n"],"names":["MAX_UID","getUID","prefix","Math","random","document","getElementById","Element","prototype","matches","closest","find","querySelectorAll","findOne","querySelector","createCustomEvent","eventName","params","cEvent","CustomEvent","window","bubbles","cancelable","detail","evt","createEvent","initCustomEvent","workingDefaultPrevented","e","initEvent","preventDefault","defaultPrevented","origPreventDefault","Event","call","Object","defineProperty","get","configurable","defaultPreventedPreservedOnDispatch","element","createElement","addEventListener","dispatchEvent","msMatchesSelector","webkitMatchesSelector","selector","parentElement","parentNode","nodeType","scopeSelectorRegex","supportScopeQuery","error","test","hasId","Boolean","id","nodeList","replace","removeAttribute"],"mappings":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