aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Rebert <[email protected]>2014-06-07 18:03:49 -0700
committerChris Rebert <[email protected]>2014-06-07 18:03:49 -0700
commit2ca6581798cf516d6ab2029bf63d1ed5f1070703 (patch)
treed42ee22fd834c0cc7bcad42f288e3d09a72d2917
parent3b99a41246cb25b1fba79d14007ed0238409e63f (diff)
parent21de05c8c09b0ff9c11651596a84442b312381bb (diff)
downloadbootstrap-2ca6581798cf516d6ab2029bf63d1ed5f1070703.tar.xz
bootstrap-2ca6581798cf516d6ab2029bf63d1ed5f1070703.zip
Merge pull request #13752 from twbs/fix-13268
Proposed fix for #13268
-rw-r--r--js/tests/unit/tooltip.js43
-rw-r--r--js/tooltip.js5
2 files changed, 42 insertions, 6 deletions
diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js
index 2e175583e..f4c840d84 100644
--- a/js/tests/unit/tooltip.js
+++ b/js/tests/unit/tooltip.js
@@ -118,9 +118,11 @@ $(function () {
test('should fire shown event', function () {
stop()
- $('<div title="tooltip title"></div>')
+ var tooltip = $('<div title="tooltip title"></div>').appendTo('#qunit-fixture')
+ tooltip
.on('shown.bs.tooltip', function () {
ok(true, 'shown was called')
+ tooltip.remove()
start()
})
.bootstrapTooltip('show')
@@ -142,12 +144,14 @@ $(function () {
test('should fire hide event', function () {
stop()
- $('<div title="tooltip title"></div>')
+ var tooltip = $('<div title="tooltip title"></div>').appendTo('#qunit-fixture')
+ tooltip
.on('shown.bs.tooltip', function () {
$(this).bootstrapTooltip('hide')
})
.on('hide.bs.tooltip', function () {
ok(true, 'hide was called')
+ tooltip.remove()
start()
})
.bootstrapTooltip('show')
@@ -155,12 +159,14 @@ $(function () {
test('should fire hidden event', function () {
stop()
- $('<div title="tooltip title"></div>')
+ var tooltip = $('<div title="tooltip title"></div>').appendTo('#qunit-fixture')
+ tooltip
.on('shown.bs.tooltip', function () {
$(this).bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
ok(true, 'hidden was called')
+ tooltip.remove()
start()
})
.bootstrapTooltip('show')
@@ -168,13 +174,15 @@ $(function () {
test('should not fire hidden event when default prevented', function () {
stop()
- $('<div title="tooltip title"></div>')
+ var tooltip = $('<div title="tooltip title"></div>').appendTo('#qunit-fixture')
+ tooltip
.on('shown.bs.tooltip', function () {
$(this).bootstrapTooltip('hide')
})
.on('hide.bs.tooltip', function (e) {
e.preventDefault()
ok(true, 'hide was called')
+ tooltip.remove()
start()
})
.on('hidden.bs.tooltip', function () {
@@ -557,4 +565,31 @@ $(function () {
$('head #test').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
+ }
+ })
})
diff --git a/js/tooltip.js b/js/tooltip.js
index 3b8ac17f6..b4ced6d2a 100644
--- a/js/tooltip.js
+++ b/js/tooltip.js
@@ -145,8 +145,9 @@
if (this.hasContent() && this.enabled) {
this.$element.trigger(e)
- if (e.isDefaultPrevented()) return
- var that = this;
+ var inDom = $.contains(document.documentElement, this.$element[0])
+ if (e.isDefaultPrevented() || !inDom) return
+ var that = this
var $tip = this.tip()