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/toast.js.map
2018-11-13 08:47:32 +02:00

1 line
No EOL
11 KiB
Text

{"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.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\n return Toast\n})($)\n\nexport default Toast\n"],"names":["Toast","$","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","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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGA;;;;;;;EAOA,IAAMA,KAAK,GAAI,UAACC,IAAD,EAAO;EACpB;;;;;EAMA,MAAMC,IAAI,GAAiB,OAA3B;EACA,MAAMC,OAAO,GAAc,OAA3B;EACA,MAAMC,QAAQ,GAAa,UAA3B;EACA,MAAMC,SAAS,SAAgBD,QAA/B;EACA,MAAME,kBAAkB,GAAGL,IAAC,CAACM,EAAF,CAAKL,IAAL,CAA3B;EAEA,MAAMM,KAAK,GAAG;EACZC,IAAAA,aAAa,oBAAmBJ,SADpB;EAEZK,IAAAA,IAAI,WAAmBL,SAFX;EAGZM,IAAAA,MAAM,aAAmBN,SAHb;EAIZO,IAAAA,IAAI,WAAmBP,SAJX;EAKZQ,IAAAA,KAAK,YAAmBR;EALZ,GAAd;EAQA,MAAMS,SAAS,GAAG;EAChBC,IAAAA,IAAI,EAAG,MADS;EAEhBL,IAAAA,IAAI,EAAG,MAFS;EAGhBE,IAAAA,IAAI,EAA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