diff options
| author | GeoSot <[email protected]> | 2021-04-19 08:20:25 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-04-19 08:20:25 +0300 |
| commit | a9d7a62658c5d93dcba5ed5fc47d84f3ddd3e0a3 (patch) | |
| tree | abc7fcf44b0dabe61ea03933d1b1c6308e2619ae /js/src/util | |
| parent | df8131a1f88e62f6bc8ae1c669bc0e534965bf1a (diff) | |
| download | bootstrap-a9d7a62658c5d93dcba5ed5fc47d84f3ddd3e0a3.tar.xz bootstrap-a9d7a62658c5d93dcba5ed5fc47d84f3ddd3e0a3.zip | |
Use the backdrop util in offcanvas, enforcing consistency (#33545)
* respect /share modal's backdrop functionality, keeping consistency
* listen click events over backdrop (only) and trigger `hide()` without add/remove event tricks
* achieve to hide foreign open offcanvas instances without glitches `if (allReadyOpen && allReadyOpen !== target)`, in case another is going to be open, when user clicks on trigger button
Diffstat (limited to 'js/src/util')
| -rw-r--r-- | js/src/util/backdrop.js | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/js/src/util/backdrop.js b/js/src/util/backdrop.js index ab14c23fe..a9d28bd10 100644 --- a/js/src/util/backdrop.js +++ b/js/src/util/backdrop.js @@ -11,19 +11,23 @@ import { emulateTransitionEnd, execute, getTransitionDurationFromElement, reflow const Default = { isVisible: true, // if false, we use the backdrop helper without adding any element to the dom isAnimated: false, - rootElement: document.body // give the choice to place backdrop under different elements + rootElement: document.body, // give the choice to place backdrop under different elements + clickCallback: null } const DefaultType = { isVisible: 'boolean', isAnimated: 'boolean', - rootElement: 'element' + rootElement: 'element', + clickCallback: '(function|null)' } const NAME = 'backdrop' const CLASS_NAME_BACKDROP = 'modal-backdrop' const CLASS_NAME_FADE = 'fade' const CLASS_NAME_SHOW = 'show' +const EVENT_MOUSEDOWN = `mousedown.bs.${NAME}` + class Backdrop { constructor(config) { this._config = this._getConfig(config) @@ -96,6 +100,10 @@ class Backdrop { this._config.rootElement.appendChild(this._getElement()) + EventHandler.on(this._getElement(), EVENT_MOUSEDOWN, () => { + execute(this._config.clickCallback) + }) + this._isAppended = true } @@ -104,6 +112,8 @@ class Backdrop { return } + EventHandler.off(this._element, EVENT_MOUSEDOWN) + this._getElement().parentNode.removeChild(this._element) this._isAppended = false } |
