From 20c099d41a0802a7f377e7f996c35cade9e0c431 Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Fri, 6 Jun 2014 14:49:59 -0700 Subject: [PATCH 1/3] add failing test for #13268 --- js/tests/unit/tooltip.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index 2e175583e5..81c0fdf736 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -557,4 +557,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 = $('').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 + } + }) }) From b23ed1b034caa90a4f6d0f97674022c80126d078 Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Fri, 6 Jun 2014 15:30:44 -0700 Subject: [PATCH 2/3] put the tooltips into the DOM in the tooltip unit tests --- js/tests/unit/tooltip.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index 81c0fdf736..f4c840d840 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() - $('
') + var tooltip = $('
').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() - $('
') + var tooltip = $('
').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() - $('
') + var tooltip = $('
').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() - $('
') + var tooltip = $('
').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 () { From 21de05c8c09b0ff9c11651596a84442b312381bb Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Fri, 6 Jun 2014 15:34:56 -0700 Subject: [PATCH 3/3] don't show tooltips/popovers whose element isn't in the DOM; fixes #13268 --- js/tooltip.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/js/tooltip.js b/js/tooltip.js index 3b8ac17f6d..b4ced6d2af 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()