Commit 2ca65817 authored by Chris Rebert's avatar Chris Rebert

Merge pull request #13752 from twbs/fix-13268

Proposed fix for #13268
parents 3b99a412 21de05c8
...@@ -118,9 +118,11 @@ $(function () { ...@@ -118,9 +118,11 @@ $(function () {
test('should fire shown event', function () { test('should fire shown event', function () {
stop() stop()
$('<div title="tooltip title"></div>') var tooltip = $('<div title="tooltip title"></div>').appendTo('#qunit-fixture')
tooltip
.on('shown.bs.tooltip', function () { .on('shown.bs.tooltip', function () {
ok(true, 'shown was called') ok(true, 'shown was called')
tooltip.remove()
start() start()
}) })
.bootstrapTooltip('show') .bootstrapTooltip('show')
...@@ -142,12 +144,14 @@ $(function () { ...@@ -142,12 +144,14 @@ $(function () {
test('should fire hide event', function () { test('should fire hide event', function () {
stop() stop()
$('<div title="tooltip title"></div>') var tooltip = $('<div title="tooltip title"></div>').appendTo('#qunit-fixture')
tooltip
.on('shown.bs.tooltip', function () { .on('shown.bs.tooltip', function () {
$(this).bootstrapTooltip('hide') $(this).bootstrapTooltip('hide')
}) })
.on('hide.bs.tooltip', function () { .on('hide.bs.tooltip', function () {
ok(true, 'hide was called') ok(true, 'hide was called')
tooltip.remove()
start() start()
}) })
.bootstrapTooltip('show') .bootstrapTooltip('show')
...@@ -155,12 +159,14 @@ $(function () { ...@@ -155,12 +159,14 @@ $(function () {
test('should fire hidden event', function () { test('should fire hidden event', function () {
stop() stop()
$('<div title="tooltip title"></div>') var tooltip = $('<div title="tooltip title"></div>').appendTo('#qunit-fixture')
tooltip
.on('shown.bs.tooltip', function () { .on('shown.bs.tooltip', function () {
$(this).bootstrapTooltip('hide') $(this).bootstrapTooltip('hide')
}) })
.on('hidden.bs.tooltip', function () { .on('hidden.bs.tooltip', function () {
ok(true, 'hidden was called') ok(true, 'hidden was called')
tooltip.remove()
start() start()
}) })
.bootstrapTooltip('show') .bootstrapTooltip('show')
...@@ -168,13 +174,15 @@ $(function () { ...@@ -168,13 +174,15 @@ $(function () {
test('should not fire hidden event when default prevented', function () { test('should not fire hidden event when default prevented', function () {
stop() stop()
$('<div title="tooltip title"></div>') var tooltip = $('<div title="tooltip title"></div>').appendTo('#qunit-fixture')
tooltip
.on('shown.bs.tooltip', function () { .on('shown.bs.tooltip', function () {
$(this).bootstrapTooltip('hide') $(this).bootstrapTooltip('hide')
}) })
.on('hide.bs.tooltip', function (e) { .on('hide.bs.tooltip', function (e) {
e.preventDefault() e.preventDefault()
ok(true, 'hide was called') ok(true, 'hide was called')
tooltip.remove()
start() start()
}) })
.on('hidden.bs.tooltip', function () { .on('hidden.bs.tooltip', function () {
...@@ -557,4 +565,31 @@ $(function () { ...@@ -557,4 +565,31 @@ $(function () {
$('head #test').remove() $('head #test').remove()
$('head #viewport-style').remove() $('head #viewport-style').remove()
}) })
test('should not error when trying to show an auto-placed tooltip that has been removed from the dom', function () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>').appendTo('#qunit-fixture')
tooltip
.one('show.bs.tooltip', function () {
tooltip.remove()
})
.bootstrapTooltip({ placement: 'auto' })
var passed = true
try {
tooltip.bootstrapTooltip('show')
}
catch (err) {
passed = false
console.log(err)
}
ok(passed, '.tooltip(\'show\') should not throw an error in this case')
try {
tooltip.remove()
}
catch (err) {
// tooltip may have already been removed
}
})
}) })
...@@ -145,8 +145,9 @@ ...@@ -145,8 +145,9 @@
if (this.hasContent() && this.enabled) { if (this.hasContent() && this.enabled) {
this.$element.trigger(e) this.$element.trigger(e)
if (e.isDefaultPrevented()) return var inDom = $.contains(document.documentElement, this.$element[0])
var that = this; if (e.isDefaultPrevented() || !inDom) return
var that = this
var $tip = this.tip() var $tip = this.tip()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment