From 4571ab0e57a5d2ff251b8c174ab0f693c5892dce Mon Sep 17 00:00:00 2001 From: Johann-S Date: Thu, 24 Aug 2017 09:40:11 +0200 Subject: [PATCH] Fix toggle for Tooltips/Popover which was called even if the Tooltip/Popover was disabled --- js/src/tooltip.js | 7 +++++-- js/tests/unit/popover.js | 23 +++++++++++++++++++++++ js/tests/unit/tooltip.js | 22 ++++++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/js/src/tooltip.js b/js/src/tooltip.js index 7dfe9dfc03..37573cf498 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -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 = (($) => { } }) } - } diff --git a/js/tests/unit/popover.js b/js/tests/unit/popover.js index a06c1b1a2e..6c0f99cba2 100644 --- a/js/tests/unit/popover.js +++ b/js/tests/unit/popover.js @@ -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 = $('@mdo') + .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) + }) }) diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index 89d5b70e8b..e4e6bdd6cc 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -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 = $('') + .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) + }) })