]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Remove the show delay for our toast plugin
authorJohann-S <johann.servoire@gmail.com>
Tue, 18 Sep 2018 12:37:40 +0000 (14:37 +0200)
committerXhmikosR <xhmikosr@gmail.com>
Tue, 13 Nov 2018 06:47:32 +0000 (08:47 +0200)
js/src/toast.js
js/tests/unit/toast.js
js/tests/visual/toast.html
site/docs/4.1/components/toasts.md

index 1e70e091f2bb94bb524ebb9b617e76dc4d22d52e..878ffe029665acf225ad103e1034f246e5bdd1d1 100644 (file)
@@ -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)
-
-        if (this._config.animation) {
-          const transitionDuration = Util.getTransitionDurationFromElement(this._element)
+      this._element.classList.add(ClassName.SHOW)
+      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,
index d9c5e1fb6ece89bf8919a75aaff7d675b7d874ae..e6bd6be1eeb17799f1421c1ed043e0b6d475b31b 100644 (file)
@@ -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 =
-      '<div class="toast" data-delay=\'{"show": 0, "hide": 1}\'>' +
-        '<div class="toast-body">' +
-          'a simple toast' +
-        '</div>' +
-      '</div>'
-
-    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'))
 
index 902194617b6a9c3476cd2f6bae7ee4e7f124c259..d069a163a7778cec6639e22b855388ced0e3a328 100644 (file)
@@ -26,7 +26,7 @@
     </div>
 
     <div class="notifications">
-      <div id="toastAutoHide" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
+      <div id="toastAutoHide" class="toast" role="alert" aria-live="assertive" aria-atomic="true" data-delay="2000">
         <div class="toast-header">
           <img class="rounded mr-2" data-src="holder.js/20x20?size=1&text=.&bg=#007aff" alt="">
           <strong class="mr-auto">Bootstrap</strong>
     <script src="../../dist/toast.js"></script>
     <script>
       $(function () {
-        $('#toastAutoHide').attr('data-delay', JSON.stringify({
-          show: 0,
-          hide: 2000
-        }))
         $('.toast').toast()
 
         $('#btnShowToast').on('click', function () {
index 84359084d299bbefe98d92c96267a656476dafaa..12fbf60d23ecca71879f48d2bbfd9cfbaf4feab7 100644 (file)
@@ -242,15 +242,11 @@ Options can be passed via data attributes or JavaScript. For data attributes, ap
     </tr>
     <tr>
       <td>delay</td>
-      <td>number | object</td>
+      <td>number</td>
       <td>
-        <code>{ show: 0, hide: 500 }</code>
-      </td>
-      <td>
-        <p>Delay showing and hiding the toast (ms)</p>
-        <p>If a number is supplied, delay is applied to both hide/show</p>
-        <p>Object structure is: <code>delay: { "show": 500, "hide": 100 }</code></p>
+        <code>500</code>
       </td>
+      <td>Delay hiding the toast (ms)</td>
     </tr>
   </tbody>
 </table>