From 557d5ac74d591b7267053e5fe6db9defcb480895 Mon Sep 17 00:00:00 2001 From: Johann-S Date: Tue, 18 Sep 2018 14:37:40 +0200 Subject: [PATCH] Remove the show delay for our toast plugin --- js/src/toast.js | 37 ++++++++++-------------------- js/tests/unit/toast.js | 27 +--------------------- js/tests/visual/toast.html | 6 +---- site/docs/4.1/components/toasts.md | 10 +++----- 4 files changed, 17 insertions(+), 63 deletions(-) diff --git a/js/src/toast.js b/js/src/toast.js index 1e70e091f2..878ffe0296 100644 --- a/js/src/toast.js +++ b/js/src/toast.js @@ -38,16 +38,13 @@ const Toast = (($) => { const DefaultType = { animation : 'boolean', autohide : 'boolean', - delay : '(number|object)' + delay : 'number' } const Default = { animation : true, autohide : true, - delay : { - show: 0, - hide: 500 - } + delay : 500 } const Selector = { @@ -95,19 +92,16 @@ const Toast = (($) => { } } - this._timeout = setTimeout(() => { - this._element.classList.add(ClassName.SHOW) + this._element.classList.add(ClassName.SHOW) + if (this._config.animation) { + const transitionDuration = Util.getTransitionDurationFromElement(this._element) - if (this._config.animation) { - const transitionDuration = Util.getTransitionDurationFromElement(this._element) - - $(this._element) - .one(Util.TRANSITION_END, complete) - .emulateTransitionEnd(transitionDuration) - } else { - complete() - } - }, this._config.delay.show) + $(this._element) + .one(Util.TRANSITION_END, complete) + .emulateTransitionEnd(transitionDuration) + } else { + complete() + } } hide(withoutTimeout) { @@ -122,7 +116,7 @@ const Toast = (($) => { } else { this._timeout = setTimeout(() => { this._close() - }, this._config.delay.hide) + }, this._config.delay) } } @@ -150,13 +144,6 @@ const Toast = (($) => { ...typeof config === 'object' && config ? config : {} } - if (typeof config.delay === 'number') { - config.delay = { - show: config.delay, - hide: config.delay - } - } - Util.typeCheckConfig( NAME, config, diff --git a/js/tests/unit/toast.js b/js/tests/unit/toast.js index d9c5e1fb6e..e6bd6be1ee 100644 --- a/js/tests/unit/toast.js +++ b/js/tests/unit/toast.js @@ -184,28 +184,6 @@ $(function () { .bootstrapToast('show') }) - QUnit.test('should allow to pass delay object in html', function (assert) { - assert.expect(1) - var done = assert.async() - - var toastHtml = - '
' + - '
' + - 'a simple toast' + - '
' + - '
' - - var $toast = $(toastHtml) - .bootstrapToast() - .appendTo($('#qunit-fixture')) - - $toast.on('shown.bs.toast', function () { - assert.strictEqual($toast.hasClass('show'), true) - done() - }) - .bootstrapToast('show') - }) - QUnit.test('should allow to config in js', function (assert) { assert.expect(1) var done = assert.async() @@ -219,10 +197,7 @@ $(function () { var $toast = $(toastHtml) .bootstrapToast({ - delay: { - show: 0, - hide: 1 - } + delay: 1 }) .appendTo($('#qunit-fixture')) diff --git a/js/tests/visual/toast.html b/js/tests/visual/toast.html index 902194617b..d069a163a7 100644 --- a/js/tests/visual/toast.html +++ b/js/tests/visual/toast.html @@ -26,7 +26,7 @@
-