mirror of
https://github.com/twbs/bootstrap.git
synced 2022-11-09 12:25:43 -05:00
1 line
No EOL
10 KiB
Text
1 line
No EOL
10 KiB
Text
{"version":3,"file":"toast.js","sources":["../src/toast.js"],"sourcesContent":["/**\n * --------------------------------------------------------------------------\n * Bootstrap (v4.1.3): toast.js\n * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)\n * --------------------------------------------------------------------------\n */\n\nimport $ from 'jquery'\nimport Util from './util'\n\n/**\n * ------------------------------------------------------------------------\n * Constants\n * ------------------------------------------------------------------------\n */\n\nconst NAME = 'toast'\nconst VERSION = '4.1.3'\nconst DATA_KEY = 'bs.toast'\nconst EVENT_KEY = `.${DATA_KEY}`\nconst JQUERY_NO_CONFLICT = $.fn[NAME]\n\nconst 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\nconst ClassName = {\n FADE : 'fade',\n HIDE : 'hide',\n SHOW : 'show'\n}\n\nconst DefaultType = {\n animation : 'boolean',\n autohide : 'boolean',\n delay : 'number'\n}\n\nconst Default = {\n animation : true,\n autohide : true,\n delay : 500\n}\n\nconst Selector = {\n DATA_DISMISS : '[data-dismiss=\"toast\"]'\n}\n\n/**\n * ------------------------------------------------------------------------\n * Class Definition\n * ------------------------------------------------------------------------\n */\n\nclass 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.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 // Static\n\n static _jQueryInterface(config) {\n return this.each(function () {\n const $element = $(this)\n let data = $element.data(DATA_KEY)\n const _config = typeof config === 'object' && config\n\n if (!data) {\n data = new Toast(this, _config)\n $element.data(DATA_KEY, data)\n }\n\n if (typeof config === 'string') {\n if (typeof data[config] === 'undefined') {\n throw new TypeError(`No method named \"${config}\"`)\n }\n\n data[config](this)\n }\n })\n }\n}\n\n/**\n * ------------------------------------------------------------------------\n * jQuery\n * ------------------------------------------------------------------------\n */\n\n$.fn[NAME] = Toast._jQueryInterface\n$.fn[NAME].Constructor = Toast\n$.fn[NAME].noConflict = () => {\n $.fn[NAME] = JQUERY_NO_CONFLICT\n return Toast._jQueryInterface\n}\n\nexport default Toast\n"],"names":["NAME","VERSION","DATA_KEY","EVENT_KEY","JQUERY_NO_CONFLICT","$","fn","Event","CLICK_DISMISS","HIDE","HIDDEN","SHOW","SHOWN","ClassName","FADE","DefaultType","animation","autohide","delay","Default","Selector","DATA_DISMISS","Toast","element","config","_element","_config","_getConfig","_timeout","_setListeners","show","trigger","classList","add","complete","hide","transitionDuration","Util","getTransitionDurationFromElement","one","TRANSITION_END","emulateTransitionEnd","withoutTimeout","contains","_close","setTimeout","dispose","clearTimeout","remove","off","removeData","data","typeCheckConfig","constructor","on","_jQueryInterface","each","$element","TypeError","Constructor","noConflict"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUA;;;;;;EAMA,IAAMA,IAAI,GAAiB,OAA3B;EACA,IAAMC,OAAO,GAAc,OAA3B;EACA,IAAMC,QAAQ,GAAa,UAA3B;EACA,IAAMC,SAAS,SAAgBD,QAA/B;EACA,IAAME,kBAAkB,GAAGC,CAAC,CAACC,EAAF,CAAKN,IAAL,CAA3B;EAEA,IAAMO,KAAK,GAAG;EACZC,EAAAA,aAAa,oBAAmBL,SADpB;EAEZM,EAAAA,IAAI,WAAmBN,SAFX;EAGZO,EAAAA,MAAM,aAAmBP,SAHb;EAIZQ,EAAAA,IAAI,WAAmBR,SAJX;EAKZS,EAAAA,KAAK,YAAmBT;EALZ,CAAd;EAQA,IAAMU,SAAS,GAAG;EAChBC,EAAAA,IAAI,EAAG,MADS;EAEhBL,EAAAA,IAAI,EAAG,MAFS;EAGhBE,EAAAA,IAAI,EAAG;EAHS,CAAlB;EAMA,IAAMI,WAAW,GAAG;EAClBC,EAAAA,SAAS,EAAG,SADM;EAElBC,EAAAA,QAAQ,EAAI,SAFM;EAG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