aboutsummaryrefslogtreecommitdiff
path: root/js/src/util/backdrop.js
diff options
context:
space:
mode:
authorXhmikosR <[email protected]>2021-10-13 15:19:28 +0300
committerGitHub <[email protected]>2021-10-13 15:19:28 +0300
commite8f702666f285a3e69866ed1f8d29fa6eaaaeabb (patch)
tree944b2dc894f49f8278d41d096e4388e9ac83157b /js/src/util/backdrop.js
parentdb44392bda22f3d5319d2880c992f76d27d2a60c (diff)
downloadbootstrap-e8f702666f285a3e69866ed1f8d29fa6eaaaeabb.tar.xz
bootstrap-e8f702666f285a3e69866ed1f8d29fa6eaaaeabb.zip
JS: minor refactoring (#35183)
* add missing comments * shorten block comments * reorder constants * reorder public/private methods * sort exports alphabetically in util/index.js * fix a couple of typos
Diffstat (limited to 'js/src/util/backdrop.js')
-rw-r--r--js/src/util/backdrop.js40
1 files changed, 24 insertions, 16 deletions
diff --git a/js/src/util/backdrop.js b/js/src/util/backdrop.js
index 04c763518..fb1b2776b 100644
--- a/js/src/util/backdrop.js
+++ b/js/src/util/backdrop.js
@@ -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)
}