alert.js.map 8.08 KB
Newer Older
roshka committed
1
{"version":3,"file":"alert.js","sources":["../src/alert.js"],"sourcesContent":["import $ from 'jquery'\nimport Util from './util'\n\n/**\n * --------------------------------------------------------------------------\n * Bootstrap (v4.1.3): alert.js\n * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)\n * --------------------------------------------------------------------------\n */\n\nconst Alert = (($) => {\n  /**\n   * ------------------------------------------------------------------------\n   * Constants\n   * ------------------------------------------------------------------------\n   */\n\n  const NAME                = 'alert'\n  const VERSION             = '4.1.3'\n  const DATA_KEY            = 'bs.alert'\n  const EVENT_KEY           = `.${DATA_KEY}`\n  const DATA_API_KEY        = '.data-api'\n  const JQUERY_NO_CONFLICT  = $.fn[NAME]\n\n  const Selector = {\n    DISMISS : '[data-dismiss=\"alert\"]'\n  }\n\n  const Event = {\n    CLOSE          : `close${EVENT_KEY}`,\n    CLOSED         : `closed${EVENT_KEY}`,\n    CLICK_DATA_API : `click${EVENT_KEY}${DATA_API_KEY}`\n  }\n\n  const ClassName = {\n    ALERT : 'alert',\n    FADE  : 'fade',\n    SHOW  : 'show'\n  }\n\n  /**\n   * ------------------------------------------------------------------------\n   * Class Definition\n   * ------------------------------------------------------------------------\n   */\n\n  class Alert {\n    constructor(element) {\n      this._element = element\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.isDefaultPrevented()) {\n        return\n      }\n\n      this._removeElement(rootElement)\n    }\n\n    dispose() {\n      $.removeData(this._element, DATA_KEY)\n      this._element = null\n    }\n\n    // Private\n\n    _getRootElement(element) {\n      const selector = Util.getSelectorFromElement(element)\n      let parent     = false\n\n      if (selector) {\n        parent = document.querySelector(selector)\n      }\n\n      if (!parent) {\n        parent = $(element).closest(`.${ClassName.ALERT}`)[0]\n      }\n\n      return parent\n    }\n\n    _triggerCloseEvent(element) {\n      const closeEvent = $.Event(Event.CLOSE)\n\n      $(element).trigger(closeEvent)\n      return closeEvent\n    }\n\n    _removeElement(element) {\n      $(element).removeClass(ClassName.SHOW)\n\n      if (!$(element).hasClass(ClassName.FADE)) {\n        this._destroyElement(element)\n        return\n      }\n\n      const transitionDuration = Util.getTransitionDurationFromElement(element)\n\n      $(element)\n        .one(Util.TRANSITION_END, (event) => this._destroyElement(element, event))\n        .emulateTransitionEnd(transitionDuration)\n    }\n\n    _destroyElement(element) {\n      $(element)\n        .detach()\n        .trigger(Event.CLOSED)\n        .remove()\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\n        if (!data) {\n          data = new Alert(this)\n          $element.data(DATA_KEY, data)\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\n  /**\n   * ------------------------------------------------------------------------\n   * Data Api implementation\n   * ------------------------------------------------------------------------\n   */\n\n  $(document).on(\n    Event.CLICK_DATA_API,\n    Selector.DISMISS,\n    Alert._handleDismiss(new Alert())\n  )\n\n  /**\n   * ------------------------------------------------------------------------\n   * jQuery\n   * ------------------------------------------------------------------------\n   */\n\n  $.fn[NAME]             = Alert._jQueryInterface\n  $.fn[NAME].Constructor = Alert\n  $.fn[NAME].noConflict  = function () {\n    $.fn[NAME] = JQUERY_NO_CONFLICT\n    return Alert._jQueryInterface\n  }\n\n  return Alert\n})($)\n\nexport default Alert\n"],"names":["Alert","$","NAME","VERSION","DATA_KEY","EVENT_KEY","DATA_API_KEY","JQUERY_NO_CONFLICT","fn","Selector","DISMISS","Event","CLOSE","CLOSED","CLICK_DATA_API","ClassName","ALERT","FADE","SHOW","element","_element","close","rootElement","_getRootElement","customEvent","_triggerCloseEvent","isDefaultPrevented","_removeElement","dispose","removeData","selector","Util","getSelectorFromElement","parent","document","querySelector","closest","closeEvent","trigger","removeClass","hasClass","_destroyElement","transitionDuration","getTransitionDurationFromElement","one","TRANSITION_END","event","emulateTransitionEnd","detach","remove","_jQueryInterface","config","each","$element","data","_handleDismiss","alertInstance","preventDefault","on","Constructor","noConflict"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;EAGA;;;;;;;EAOA,IAAMA,QAAS,UAACC,IAAD,EAAO;EACpB;;;;;EAMA,MAAMC,OAAsB,OAA5B;EACA,MAAMC,UAAsB,OAA5B;EACA,MAAMC,WAAsB,UAA5B;EACA,MAAMC,kBAA0BD,QAAhC;EACA,MAAME,eAAsB,WAA5B;EACA,MAAMC,qBAAsBN,KAAEO,EAAF,CAAKN,IAAL,CAA5B;EAEA,MAAMO,WAAW;EACfC,aAAU;EADK,GAAjB;EAIA,MAAMC,QAAQ;EACZC,qBAAyBP,SADb;EAEZQ,uBAA0BR,SAFd;EAGZS,8BAAyBT,SAAzB,GAAqCC;EAHzB,GAAd;EAMA,MAAMS,YAAY;EAChBC,WAAQ,OADQ;EAEhBC,UAAQ,MAFQ;EAGhBC,UAAQ;EAGV;;;;;;EANkB,GAAlB;;EAxBoB,MAoCdlB,KApCc;EAAA;EAAA;EAqClB,mBAAYmB,OAAZ,EAAqB;EACnB,WAAKC,QAAL,GAAgBD,OAAhB;EACD,KAvCiB;;;EAAA;;EA+ClB;EA/CkB,WAiDlBE,KAjDkB,kBAiDZF,OAjDY,EAiDH;EACb,UAAIG,cAAc,KAAKF,QAAvB;;EACA,UAAID,OAAJ,EAAa;EACXG,sBAAc,KAAKC,eAAL,CAAqBJ,OAArB,CAAd;EACD;;EAED,UAAMK,cAAc,KAAKC,kBAAL,CAAwBH,WAAxB,CAApB;;EAEA,UAAIE,YAAYE,kBAAZ,EAAJ,EAAsC;EACpC;EACD;;EAED,WAAKC,cAAL,CAAoBL,WAApB;EACD,KA9DiB;;EAAA,WAgElBM,OAhEk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