Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/js/src
diff options
context:
space:
mode:
authorGeoSot <geo.sotis@gmail.com>2022-03-01 18:08:12 +0300
committerGitHub <noreply@github.com>2022-03-01 18:08:12 +0300
commit63f30ac8ee28d12b5044c1f98e3b6ca7720a1f81 (patch)
tree3277f2f1d92aceb816c41208f9c4fa404fbe7dec /js/src
parentc644f09d88a93445b415faa796f1d246ca34e2e7 (diff)
Modal: refactor listeners to reduce some code noise (#35902)
Diffstat (limited to 'js/src')
-rw-r--r--js/src/modal.js29
1 files changed, 8 insertions, 21 deletions
diff --git a/js/src/modal.js b/js/src/modal.js
index 054750c5f7..ea8e0a0463 100644
--- a/js/src/modal.js
+++ b/js/src/modal.js
@@ -69,6 +69,8 @@ class Modal extends BaseComponent {
this._isShown = false
this._isTransitioning = false
this._scrollBar = new ScrollBarHelper()
+
+ this._addEventListeners()
}
// Getters
@@ -111,9 +113,6 @@ class Modal extends BaseComponent {
this._adjustDialog()
- this._toggleEscapeEventListener(true)
- this._toggleResizeEventListener(true)
-
this._backdrop.show(() => this._showElement(relatedTarget))
}
@@ -130,10 +129,6 @@ class Modal extends BaseComponent {
this._isShown = false
this._isTransitioning = true
-
- this._toggleEscapeEventListener(false)
- this._toggleResizeEventListener(false)
-
this._focustrap.deactivate()
this._element.classList.remove(CLASS_NAME_SHOW)
@@ -217,12 +212,7 @@ class Modal extends BaseComponent {
this._queueCallback(transitionComplete, this._dialog, this._isAnimated())
}
- _toggleEscapeEventListener(enable) {
- if (!enable) {
- EventHandler.off(this._element, EVENT_KEYDOWN_DISMISS)
- return
- }
-
+ _addEventListeners() {
EventHandler.on(this._element, EVENT_KEYDOWN_DISMISS, event => {
if (event.key !== ESCAPE_KEY) {
return
@@ -236,15 +226,12 @@ class Modal extends BaseComponent {
this._triggerBackdropTransition()
})
- }
-
- _toggleResizeEventListener(enable) {
- if (enable) {
- EventHandler.on(window, EVENT_RESIZE, () => this._adjustDialog())
- return
- }
- EventHandler.off(window, EVENT_RESIZE)
+ EventHandler.on(window, EVENT_RESIZE, () => {
+ if (this._isShown && !this._isTransitioning) {
+ this._adjustDialog()
+ }
+ })
}
_hideModal() {