From 0962b1ae9086bcf527cd6c6871671f54df1be400 Mon Sep 17 00:00:00 2001 From: Johann-S Date: Tue, 10 Oct 2017 13:19:39 +0200 Subject: [PATCH] Modal plugin set _isTransitioning after the trigger of hide event --- js/src/modal.js | 12 ++++++------ js/tests/visual/modal.html | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/js/src/modal.js b/js/src/modal.js index 1ea630c4154d..399adc4c1298 100644 --- a/js/src/modal.js +++ b/js/src/modal.js @@ -169,12 +169,6 @@ const Modal = (() => { return } - const transition = Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE) - - if (transition) { - this._isTransitioning = true - } - const hideEvent = $.Event(Event.HIDE) $(this._element).trigger(hideEvent) @@ -185,6 +179,12 @@ const Modal = (() => { this._isShown = false + const transition = Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE) + + if (transition) { + this._isTransitioning = true + } + this._setEscapeEvent() this._setResizeEvent() diff --git a/js/tests/visual/modal.html b/js/tests/visual/modal.html index 6e9f0f7107c4..fcc96035bd99 100644 --- a/js/tests/visual/modal.html +++ b/js/tests/visual/modal.html @@ -171,6 +171,12 @@ + +

+ + @@ -203,6 +209,22 @@ $('#firefoxModal').on('focus', reportFirefoxTestResult.bind(false)) $('#ff-bug-input').on('focus', reportFirefoxTestResult.bind(true)) }) + + $('#btnPreventModal').on('click', function () { + $('#firefoxModal').one('shown.bs.modal', function () { + $(this).modal('hide') + }) + .one('hide.bs.modal', function (event) { + event.preventDefault() + if ($(this).data('bs.modal')._isTransitioning) { + console.error('Modal plugin should not set _isTransitioning when hide event is prevented') + } else { + console.log('Test passed') + $(this).modal('hide') // work as expected + } + }) + .modal('show') + }) })