From ffc8d507c713ee6e93e04fb61c2e6df3e1020007 Mon Sep 17 00:00:00 2001 From: Johann-S Date: Fri, 26 Oct 2018 16:43:20 +0200 Subject: [PATCH] calculate modal transition duration based on modal-dialog element --- js/src/modal.js | 2 +- js/tests/unit/modal.js | 46 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/js/src/modal.js b/js/src/modal.js index ae71a268be..2c71baf736 100644 --- a/js/src/modal.js +++ b/js/src/modal.js @@ -260,7 +260,7 @@ class Modal { } if (transition) { - const transitionDuration = Util.getTransitionDurationFromElement(this._element) + const transitionDuration = Util.getTransitionDurationFromElement(this._dialog) $(this._dialog) .one(Util.TRANSITION_END, transitionComplete) diff --git a/js/tests/unit/modal.js b/js/tests/unit/modal.js index c8f247a350..7c8299109e 100644 --- a/js/tests/unit/modal.js +++ b/js/tests/unit/modal.js @@ -1,6 +1,8 @@ $(function () { 'use strict' + window.Util = typeof bootstrap !== 'undefined' ? bootstrap.Util : Util + QUnit.module('modal plugin') QUnit.test('should be defined on jquery object', function (assert) { @@ -651,4 +653,48 @@ $(function () { .bootstrapModal('show') .bootstrapModal('hide') }) + + QUnit.test('transition duration should be the modal-dialog duration before triggering shown event', function (assert) { + assert.expect(2) + var done = assert.async() + var style = [ + '' + ].join('') + + var $style = $(style).appendTo('head') + var modalHTML = [ + '' + ].join('') + + var beginTimestamp = 0 + var $modal = $(modalHTML).appendTo('#qunit-fixture') + var $modalDialog = $('.modal-dialog') + var transitionDuration = Util.getTransitionDurationFromElement($modalDialog[0]) + + assert.strictEqual(transitionDuration, 300) + + $modal.on('shown.bs.modal', function () { + var diff = Date.now() - beginTimestamp + assert.ok(diff < 400) + $style.remove() + done() + }) + .bootstrapModal('show') + + beginTimestamp = Date.now() + }) })