mirror of
https://github.com/twbs/bootstrap.git
synced 2025-01-07 00:46:15 +01:00
1 line
11 KiB
Plaintext
1 line
11 KiB
Plaintext
|
{"version":3,"file":"toast.js","sources":["../src/toast.js"],"sourcesContent":["import $ from 'jquery'\nimport Util from './util'\n\n/**\n * --------------------------------------------------------------------------\n * Bootstrap (v4.1.3): toast.js\n * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)\n * --------------------------------------------------------------------------\n */\n\nconst Toast = (($) => {\n /**\n * ------------------------------------------------------------------------\n * Constants\n * ------------------------------------------------------------------------\n */\n\n const NAME = 'toast'\n const VERSION = '4.1.3'\n const DATA_KEY = 'bs.toast'\n const EVENT_KEY = `.${DATA_KEY}`\n const JQUERY_NO_CONFLICT = $.fn[NAME]\n\n const Event = {\n CLICK_DISMISS : `click.dismiss${EVENT_KEY}`,\n HIDE : `hide${EVENT_KEY}`,\n HIDDEN : `hidden${EVENT_KEY}`,\n SHOW : `show${EVENT_KEY}`,\n SHOWN : `shown${EVENT_KEY}`\n }\n\n const ClassName = {\n FADE : 'fade',\n HIDE : 'hide',\n SHOW : 'show'\n }\n\n const DefaultType = {\n animation : 'boolean',\n autohide : 'boolean',\n delay : 'number'\n }\n\n const Default = {\n animation : true,\n autohide : true,\n delay : 500\n }\n\n const Selector = {\n DATA_DISMISS : '[data-dismiss=\"toast\"]'\n }\n\n /**\n * ------------------------------------------------------------------------\n * Class Definition\n * ------------------------------------------------------------------------\n */\n\n class Toast {\n constructor(element, config) {\n this._element = element\n this._config = this._getConfig(config)\n this._timeout = null\n this._setListeners()\n }\n\n // Getters\n\n static get VERSION() {\n return VERSION\n }\n\n static get DefaultType() {\n return DefaultType\n }\n\n // Public\n\n show() {\n $(this._element).trigger(Event.SHOW)\n\n if (this._config.animation) {\n this._element.classList.add(ClassName.FADE)\n }\n\n const complete = () => {\n $(this._element).trigger(Event.SHOWN)\n\n if (this._config.autohide) {\n this.hide()\n }\n }\n\n this._element.classList.add(ClassName.SHOW)\n if (this._config.animation) {\n const transitionDuration = Util.getTransitionDurationFromElement(this._element)\n\n $(this._element)\n .one(Util.TRANSITION_END, complete)\n .emulateTransitionEnd(transitionDuration)\n } else {\n complete()\n }\n }\n\n hide(withoutTimeout) {\n if (!this._element.classList.contains(ClassName.SHOW)) {\n return\n }\n\n $(this._element).trigger(Event.HIDE)\n\n if (withoutTimeout) {\n this._close()\n } else {\n this._timeout = setTimeout(() => {\n this._close()\n }, this._config.delay)\n }\n }\n\n dispose() {\n clearTimeout(this._timeout)\n this._timeout = null\n\n if (this._element.classList.contains(ClassName.SHOW)) {\n this._element.classList.remove(ClassName.SHOW)\n }\n\n $(this._element).off(Event.CLICK_DISMISS)\n\n $.removeData(this._element, DATA_KEY)\n this._element = null\n this._config = null\n }\n\n // Private\n\n _getConfig(config) {\n config = {\n ...Default,\n ...$(this._element).data(),\n ...typeof config === 'object' && config ? config : {}\n }\n\n Util.typeCheckConfig(\n NAME,\n config,\n this.constructor.DefaultType\n )\n\n return config\n }\n\n _setListeners() {\n $(this._element).on(\n Event.CLICK_DISMISS,\n Selector.DATA_DISMISS,\n () => this.hide(true)\n )\n }\n\n _close() {\n const complete = () => {\n $(this._element).trigger(Event.HIDDEN)\n }\n\n this._element.classList.remove(ClassName.SHOW)\n\n if (this._config
|