aboutsummaryrefslogblamecommitdiffstats
path: root/vendor/twbs/bootstrap/js/dist/util/backdrop.js.map
blob: 66eca35955e1095c3fa7574cee29931d57ff6dd5 (plain) (tree)
1
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
{"version":3,"file":"backdrop.js","sources":["../../src/util/backdrop.js"],"sourcesContent":["/**\n * --------------------------------------------------------------------------\n * Bootstrap (v5.2.2): util/backdrop.js\n * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)\n * --------------------------------------------------------------------------\n */\n\nimport EventHandler from '../dom/event-handler'\nimport { execute, executeAfterTransition, getElement, reflow } from './index'\nimport Config from './config'\n\n/**\n * Constants\n */\n\nconst NAME = 'backdrop'\nconst CLASS_NAME_FADE = 'fade'\nconst CLASS_NAME_SHOW = 'show'\nconst EVENT_MOUSEDOWN = `mousedown.bs.${NAME}`\n\nconst Default = {\n  className: 'modal-backdrop',\n  clickCallback: null,\n  isAnimated: false,\n  isVisible: true, // if false, we use the backdrop helper without adding any element to the dom\n  rootElement: 'body' // give the choice to place backdrop under different elements\n}\n\nconst DefaultType = {\n  className: 'string',\n  clickCallback: '(function|null)',\n  isAnimated: 'boolean',\n  isVisible: 'boolean',\n  rootElement: '(element|string)'\n}\n\n/**\n * Class definition\n */\n\nclass Backdrop extends Config {\n  constructor(config) {\n    super()\n    this._config = this._getConfig(config)\n    this._isAppended = false\n    this._element = null\n  }\n\n  // Getters\n  static get Default() {\n    return Default\n  }\n\n  static get DefaultType() {\n    return DefaultType\n  }\n\n  static get NAME() {\n    return NAME\n  }\n\n  // Public\n  show(callback) {\n    if (!this._config.isVisible) {\n      execute(callback)\n      return\n    }\n\n    this._append()\n\n    const element = this._getElement()\n    if (this._config.isAnimated) {\n      reflow(element)\n    }\n\n    element.classList.add(CLASS_NAME_SHOW)\n\n    this._emulateAnimation(() => {\n      execute(callback)\n    })\n  }\n\n  hide(callback) {\n    if (!this._config.isVisible) {\n      execute(callback)\n      return\n    }\n\n    this._getElement().classList.remove(CLASS_NAME_SHOW)\n\n    this._emulateAnimation(() => {\n      this.dispose()\n      execute(callback)\n    })\n  }\n\n  dispose() {\n    if (!this._isAppended) {\n      return\n    }\n\n    EventHandler.off(this._element, EVENT_MOUSEDOWN)\n\n    this._element.remove()\n    this._isAppended = false\n  }\n\n  // Private\n  _getElement() {\n    if (!this._element) {\n      const backdrop = document.createElement('div')\n      backdrop.className = this._config.className\n      if (this._config.isAnimated) {\n        backdrop.classList.add(CLASS_NAME_FADE)\n      }\n\n      this._element = backdrop\n    }\n\n    return this._element\n  }\n\n  _configAfterMerge(config) {\n    // use getElement() with the default \"body\" to get a fresh Element on each instantiation\n    config.rootElement = getElement(config.rootElement)\n    return config\n  }\n\n  _append() {\n    if (this._isAppended) {\n      return\n    }\n\n    const element = this._getElement()\n    this._config.rootElement.append(element)\n\n    EventHandler.on(element, EVENT_MOUSEDOWN, () => {\n      execute(this._config.clickCallback)\n    })\n\n    this._isAppended = true\n  }\n\n  _emulateAnimation(callback) {\n    executeAfterTransition(callback, this._getElement(), this._config.isAnimated)\n  }\n}\n\nexport default Backdrop\n"],"names":["NAME","CLASS_NAME_FADE","CLASS_NAME_SHOW","EVENT_MOUSEDOWN","Default","className","clickCallback","isAnimated","isVisible","rootElement","DefaultType","Backdrop","Config","constructor","config","_config","_getConfig","_isAppended","_element","show","callback","execute","_append","element","_getElement","reflow","classList","add","_emulateAnimation","hide","remove","dispose","EventHandler","off","backdrop","document","createElement","_configAfterMerge","getElement","append","on","executeAfterTransition"],"mappings":";;;;;;;;;;;;;;;;EAAA;EACA;EACA;EACA;EACA;EACA;EAMA;EACA;EACA;;EAEA,MAAMA,IAAI,GAAG,UAAb,CAAA;EACA,MAAMC,eAAe,GAAG,MAAxB,CAAA;EACA,MAAMC,eAAe,GAAG,MAAxB,CAAA;EACA,MAAMC,eAAe,GAAI,CAAeH,aAAAA,EAAAA,IAAK,CAA7C,CAAA,CAAA;EAEA,MAAMI,OAAO,GAAG;EACdC,EAAAA,SAAS,EAAE,gBADG;EAEdC,EAAAA,aAAa,EAAE,IAFD;EAGdC,EAAAA,UAAU,EAAE,KAHE;EAIdC,EAAAA,SAAS,EAAE,IAJG;EAIG;IACjBC,WAAW,EAAE,MALC;;EAAA,CAAhB,CAAA;EAQA,MAAMC,WAAW,GAAG;EAClBL,EAAAA,SAAS,EAAE,QADO;EAElBC,EAAAA,aAAa,EAAE,iBAFG;EAGlBC,EAAAA,UAAU,EAAE,SAHM;EAIlBC,EAAAA,SAAS,EAAE,SAJO;EAKlBC,EAAAA,WAAW,EAAE,kBAAA;EALK,CAApB,CAAA;EAQA;EACA;EACA;;EAEA,MAAME,QAAN,SAAuBC,uBAAvB,CAA8B;IAC5BC,WAAW,CAACC,MAAD,EAAS;EAClB,IAAA,KAAA,EAAA,CAAA;EACA,IAAA,IAAA,CAAKC,OAAL,GAAe,IAAA,CAAKC,UAAL,CAAgBF,MAAhB,CAAf,CAAA;MACA,IAAKG,CAAAA,WAAL,GAAmB,KAAnB,CAAA;MACA,IAAKC,CAAAA,QAAL,GAAgB,IAAhB,CAAA;EACD,GAN2B;;;EASV,EAAA,WAAPd,OAAO,GAAG;EACnB,IAAA,OA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