mirror of
https://github.com/twbs/bootstrap.git
synced 2024-11-29 11:24:18 +01:00
1 line
16 KiB
Plaintext
1 line
16 KiB
Plaintext
{"version":3,"file":"alert.js","sources":["../src/util/index.js","../src/alert.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'\nconst { jQuery } = window\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 getSelectorFromElement = 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() : ''\n }\n\n try {\n return document.querySelector(selector) ? selector : null\n } catch (error) {\n return null\n }\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\nexport {\n jQuery,\n TRANSITION_END,\n getUID,\n getSelectorFromElement,\n getTransitionDurationFromElement,\n triggerTransitionEnd,\n isElement,\n emulateTransitionEnd,\n typeCheckConfig,\n makeArray,\n isVisible,\n findShadowRoot,\n noop,\n reflow\n}\n","/**\n * --------------------------------------------------------------------------\n * Bootstrap (v4.3.1): alert.js\n * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)\n * --------------------------------------------------------------------------\n */\n\nimport {\n jQuery as $,\n TRANSITION_END,\n emulateTransitionEnd,\n getSelectorFromElement,\n getTransitionDurationFromElement\n} from './util/index'\nimport Data from './dom/data'\nimport EventHandler from './dom/event-handler'\nimport SelectorEngine from './dom/selector-engine'\n\n/**\n * ------------------------------------------------------------------------\n * Constants\n * ------------------------------------------------------------------------\n */\n\nconst NAME = 'alert'\nconst VERSION = '4.3.1'\nconst DATA_KEY = 'bs.alert'\nconst EVENT_KEY = `.${DATA_KEY}`\nconst DATA_API_KEY = '.data-api'\n\nconst Selector = {\n DISMISS: '[data-dismiss=\"alert\"]'\n}\n\nconst Event = {\n CLOSE: `close${EVENT_KEY}`,\n CLOSED: `closed${EVENT_KEY}`,\n CLICK_DATA_API: `click${EVENT_KEY}${DATA_API_KEY}`\n}\n\nconst ClassName = {\n ALERT: 'alert',\n FADE: 'fade',\n SHOW: 'show'\n}\n\n/**\n * ------------------------------------------------------------------------\n * Class Definition\n * ------------------------------------------------------------------------\n */\n\nclass Alert {\n constructor(element) {\n this._element = element\n if (this._element) {\n Data.setData(element, DATA_KEY, this)\n }\n }\n\n // Getters\n\n static get VERSION() {\n return VERSION\n }\n\n // Public\n\n close(element) {\n let rootElement = this._element\n if (element) {\n rootElement = this._getRootElement(element)\n }\n\n const customEvent = this._triggerCloseEvent(rootElement)\n\n if (customEvent === null || customEvent.defaultPrevented) {\n return\n }\n\n this._removeElement(rootElement)\n }\n\n dispose() {\n Data.removeData(this._element, DATA_KEY)\n this._element = null\n }\n\n // Private\n\n _getRootElement(element) {\n const selector = getSelectorFromElement(element)\n let parent = false\n\n if (selector) {\n parent = SelectorEngine.findOne(selector)\n }\n\n if (!parent) {\n parent = SelectorEngine.closest(element, `.${ClassName.ALERT}`)\n }\n\n return parent\n }\n\n _triggerCloseEvent(element) {\n return EventHandler.trigger(element, Event.CLOSE)\n }\n\n _removeElement(element) {\n element.classList.remove(ClassName.SHOW)\n\n if (!element.classList.contains(ClassName.FADE)) {\n this._destroyElement(element)\n return\n }\n\n const transitionDuration = getTransitionDurationFromElement(element)\n\n EventHandler\n .one(element, TRANSITION_END, event => this._destroyElement(element, event))\n emulateTransitionEnd(element, transitionDuration)\n }\n\n _destroyElement(element) {\n if (element.parentNode) {\n element.parentNode.removeChild(element)\n }\n\n EventHandler.trigger(element, Event.CLOSED)\n }\n\n // Static\n\n static _jQueryInterface(config) {\n return this.each(function () {\n let data = Data.getData(this, DATA_KEY)\n\n if (!data) {\n data = new Alert(this)\n }\n\n if (config === 'close') {\n data[config](this)\n }\n })\n }\n\n static _handleDismiss(alertInstance) {\n return function (event) {\n if (event) {\n event.preventDefault()\n }\n\n alertInstance.close(this)\n }\n }\n\n static _getInstance(element) {\n return Data.getData(element, DATA_KEY)\n }\n}\n\n/**\n * ------------------------------------------------------------------------\n * Data Api implementation\n * ------------------------------------------------------------------------\n */\nEventHandler\n .on(document, Event.CLICK_DATA_API, Selector.DISMISS, Alert._handleDismiss(new Alert()))\n\n/**\n * ------------------------------------------------------------------------\n * jQuery\n * ------------------------------------------------------------------------\n * add .alert to jQuery only if jQuery is present\n */\n\nif (typeof $ !== 'undefined') {\n const JQUERY_NO_CONFLICT = $.fn[NAME]\n $.fn[NAME] = Alert._jQueryInterface\n $.fn[NAME].Constructor = Alert\n $.fn[NAME].noConflict = () => {\n $.fn[NAME] = JQUERY_NO_CONFLICT\n return Alert._jQueryInterface\n }\n}\n\nexport default Alert\n"],"names":["MILLISECONDS_MULTIPLIER","TRANSITION_END","window","jQuery","getSelectorFromElement","element","selector","getAttribute","hrefAttr","trim","document","querySelector","error","getTransitionDurationFromElement","getComputedStyle","transitionDuration","transitionDelay","floatTransitionDuration","parseFloat","floatTransitionDelay","split","triggerTransitionEnd","evt","createEvent","initEvent","dispatchEvent","emulateTransitionEnd","duration","called","durationPadding","emulatedDuration","listener","removeEventListener","addEventListener","setTimeout","NAME","VERSION","DATA_KEY","EVENT_KEY","DATA_API_KEY","Selector","DISMISS","Event","CLOSE","CLOSED","CLICK_DATA_API","ClassName","ALERT","FADE","SHOW","Alert","_element","Data","setData","close","rootElement","_getRootElement","customEvent","_triggerCloseEvent","defaultPrevented","_removeElement","dispose","removeData","parent","SelectorEngine","findOne","closest","EventHandler","trigger","classList","remove","contains","_destroyElement","one","event","parentNode","removeChild","_jQueryInterface","config","each","data","getData","_handleDismiss","alertInstance","preventDefault","_getInstance","on","$","JQUERY_NO_CONFLICT","fn","Constructor","noConflict"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAA;;;;;;AAOA,EACA,IAAMA,uBAAuB,GAAG,IAAhC;EACA,IAAMC,cAAc,GAAG,eAAvB;gBACmBC;MAAXC,iBAAAA;;EAoBR,IAAMC,sBAAsB,GAAG,SAAzBA,sBAAyB,CAAAC,OAAO,EAAI;EACxC,MAAIC,QAAQ,GAAGD,OAAO,CAACE,YAAR,CAAqB,aAArB,CAAf;;EAEA,MAAI,CAACD,QAAD,IAAaA,QAAQ,KAAK,GAA9B,EAAmC;EACjC,QAAME,QAAQ,GAAGH,OAAO,CAACE,YAAR,CAAqB,MAArB,CAAjB;EAEAD,IAAAA,QAAQ,GAAGE,QAAQ,IAAIA,QAAQ,KAAK,GAAzB,GAA+BA,QAAQ,CAACC,IAAT,EAA/B,GAAiD,EAA5D;EACD;;EAED,MAAI;EACF,WAAOC,QAAQ,CAACC,aAAT,CAAuBL,QAAvB,IAAmCA,QAAnC,GAA8C,IAArD;EACD,GAFD,CAEE,OAAOM,KAAP,EAAc;EACd,WAAO,IAAP;EACD;EACF,CAdD;;EAgBA,IAAMC,gCAAgC,GAAG,SAAnCA,gCAAmC,CAAAR,OAAO,EAAI;EAClD,MAAI,CAACA,OAAL,EAAc;EACZ,WAAO,CAA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