aboutsummaryrefslogtreecommitdiff
path: root/js/src/util/backdrop.js
diff options
context:
space:
mode:
authorPriyansh <[email protected]>2021-11-28 14:27:57 -0500
committerGitHub <[email protected]>2021-11-28 14:27:57 -0500
commitd53094ec16ba385faae2973ddee648698b32ab24 (patch)
tree9fe907f4f5a4ed57fff915526f36eca9dd05f07e /js/src/util/backdrop.js
parent52cd86f8710f8049a744b5bcb9f4a7ce19114b6e (diff)
parent5290080d4df3047d04c8a232bca5dc7f8eaa4bc6 (diff)
downloadbootstrap-d53094ec16ba385faae2973ddee648698b32ab24.tar.xz
bootstrap-d53094ec16ba385faae2973ddee648698b32ab24.zip
Merge branch 'twbs:main' into main
Diffstat (limited to 'js/src/util/backdrop.js')
-rw-r--r--js/src/util/backdrop.js42
1 files changed, 25 insertions, 17 deletions
diff --git a/js/src/util/backdrop.js b/js/src/util/backdrop.js
index e5ca0c860..fb1b2776b 100644
--- a/js/src/util/backdrop.js
+++ b/js/src/util/backdrop.js
@@ -1,6 +1,6 @@
/**
* --------------------------------------------------------------------------
- * Bootstrap (v5.1.2): util/backdrop.js
+ * Bootstrap (v5.1.3): util/backdrop.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* --------------------------------------------------------------------------
*/
@@ -8,6 +8,15 @@
import EventHandler from '../dom/event-handler'
import { execute, executeAfterTransition, getElement, reflow, typeCheckConfig } from './index'
+/**
+ * Constants
+ */
+
+const NAME = 'backdrop'
+const CLASS_NAME_FADE = 'fade'
+const CLASS_NAME_SHOW = 'show'
+const EVENT_MOUSEDOWN = `mousedown.bs.${NAME}`
+
const Default = {
className: 'modal-backdrop',
isVisible: true, // if false, we use the backdrop helper without adding any element to the dom
@@ -23,11 +32,10 @@ const DefaultType = {
rootElement: '(element|string)',
clickCallback: '(function|null)'
}
-const NAME = 'backdrop'
-const CLASS_NAME_FADE = 'fade'
-const CLASS_NAME_SHOW = 'show'
-const EVENT_MOUSEDOWN = `mousedown.bs.${NAME}`
+/**
+ * Class definition
+ */
class Backdrop {
constructor(config) {
@@ -36,6 +44,7 @@ class Backdrop {
this._element = null
}
+ // Public
show(callback) {
if (!this._config.isVisible) {
execute(callback)
@@ -69,8 +78,18 @@ class Backdrop {
})
}
- // Private
+ dispose() {
+ if (!this._isAppended) {
+ return
+ }
+ EventHandler.off(this._element, EVENT_MOUSEDOWN)
+
+ this._element.remove()
+ this._isAppended = false
+ }
+
+ // Private
_getElement() {
if (!this._element) {
const backdrop = document.createElement('div')
@@ -111,17 +130,6 @@ class Backdrop {
this._isAppended = true
}
- dispose() {
- if (!this._isAppended) {
- return
- }
-
- EventHandler.off(this._element, EVENT_MOUSEDOWN)
-
- this._element.remove()
- this._isAppended = false
- }
-
_emulateAnimation(callback) {
executeAfterTransition(callback, this._getElement(), this._config.isAnimated)
}