Skip to content

Commit

Permalink
Fix toggle for Tooltips/Popover which was called even if the Tooltip/…
Browse files Browse the repository at this point in the history
…Popover was disabled
  • Loading branch information
Johann-S committed Aug 24, 2017
1 parent 3a6fc26 commit 4571ab0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
7 changes: 5 additions & 2 deletions js/src/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -706,7 +710,6 @@ const Tooltip = (($) => {
}
})
}

}


Expand Down
23 changes: 23 additions & 0 deletions js/tests/unit/popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
22 changes: 22 additions & 0 deletions js/tests/unit/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})

0 comments on commit 4571ab0

Please sign in to comment.