]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Fix toggle for Tooltips/Popover which was called even if the Tooltip/Popover was...
authorJohann-S <johann.servoire@gmail.com>
Thu, 24 Aug 2017 07:40:11 +0000 (09:40 +0200)
committerJohann-S <johann.servoire@gmail.com>
Thu, 24 Aug 2017 08:33:49 +0000 (09:33 +0100)
js/src/tooltip.js
js/tests/unit/popover.js
js/tests/unit/tooltip.js

index 7dfe9dfc03436cac551c3490b2218b71bef3ecab..37573cf49852218ec4d464951732dd14b474f8e9 100644 (file)
@@ -184,6 +184,10 @@ const Tooltip = (($) => {
     }
 
     toggle(event) {
+      if (!this._isEnabled) {
+        return
+      }
+
       if (event) {
         const dataKey = this.constructor.DATA_KEY
         let context = $(event.currentTarget).data(dataKey)
@@ -234,8 +238,8 @@ const Tooltip = (($) => {
       if (this._popper !== null) {
         this._popper.destroy()
       }
-      this._popper        = null
 
+      this._popper = null
       this.element = null
       this.config  = null
       this.tip     = null
@@ -706,7 +710,6 @@ const Tooltip = (($) => {
         }
       })
     }
-
   }
 
 
index a06c1b1a2e8932bc02305a6668ce4f5be71c4aa2..6c0f99cba2c8b48b8feb919902489df43fcdba38 100644 (file)
@@ -387,4 +387,27 @@ $(function () {
 
     $popover.bootstrapPopover('show')
   })
+
+  QUnit.test('popover should be shown right away after the call of disable/enable', function (assert) {
+    assert.expect(2)
+    var done = assert.async()
+    var $popover = $('<a href="#">@mdo</a>')
+      .appendTo('#qunit-fixture')
+      .bootstrapPopover({
+        title: 'Test popover',
+        content: 'with disable/enable'
+      })
+      .on('shown.bs.popover', function () {
+        assert.strictEqual($('.popover').hasClass('show'), true)
+        done()
+      })
+
+    $popover.bootstrapPopover('disable')
+    $popover.trigger($.Event('click'))
+    setTimeout(function () {
+      assert.strictEqual($('.popover').length === 0, true)
+      $popover.bootstrapPopover('enable')
+      $popover.trigger($.Event('click'))
+    }, 200)
+  })
 })
index 89d5b70e8b9db51861b11738877af4d8a4a952bf..e4e6bdd6cc8b405dd16d6a52e843f8ca0560c55c 100644 (file)
@@ -826,4 +826,26 @@ $(function () {
 
     $el.bootstrapTooltip('show')
   })
+
+  QUnit.test('tooltip should be shown right away after the call of disable/enable', function (assert) {
+    assert.expect(2)
+    var done = assert.async()
+
+    var $trigger = $('<a href="#" rel="tooltip" data-trigger="click" title="Another tooltip"/>')
+      .appendTo('#qunit-fixture')
+      .bootstrapTooltip()
+      .on('shown.bs.tooltip', function () {
+        assert.strictEqual($('.tooltip').hasClass('show'), true)
+        done()
+      })
+
+
+    $trigger.bootstrapTooltip('disable')
+    $trigger.trigger($.Event('click'))
+    setTimeout(function () {
+      assert.strictEqual($('.tooltip').length === 0, true)
+      $trigger.bootstrapTooltip('enable')
+      $trigger.trigger($.Event('click'))
+    }, 200)
+  })
 })