From 2c830543aad5b1b93cd77cb13b34db456e31839e Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Tue, 3 Mar 2015 13:32:24 -0800 Subject: [PATCH] Hiding an uninitialized tooltip/popover no longer initializes it; fixes #15874 --- js/popover.js | 2 +- js/tests/unit/popover.js | 12 ++++++++++++ js/tests/unit/tooltip.js | 12 ++++++++++++ js/tooltip.js | 2 +- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/js/popover.js b/js/popover.js index 09be24433bff..8b1841084301 100644 --- a/js/popover.js +++ b/js/popover.js @@ -85,7 +85,7 @@ var data = $this.data('bs.popover') var options = typeof option == 'object' && option - if (!data && option == 'destroy') return + if (!data && (option == 'destroy' || option == 'hide')) return if (!data) $this.data('bs.popover', (data = new Popover(this, options))) if (typeof option == 'string') data[option]() }) diff --git a/js/tests/unit/popover.js b/js/tests/unit/popover.js index ce89c8dbd661..73a67c98406a 100644 --- a/js/tests/unit/popover.js +++ b/js/tests/unit/popover.js @@ -247,4 +247,16 @@ $(function () { }, new Error('`selector` option must be specified when initializing popover on the window.document object!')) }) + QUnit.test('should do nothing when an attempt is made to hide an uninitialized popover', function (assert) { + assert.expect(1) + + var $popover = $('some text') + .appendTo('#qunit-fixture') + .on('hidden.bs.popover shown.bs.popover', function () { + assert.ok(false, 'should not fire any popover events') + }) + .bootstrapPopover('hide') + assert.strictEqual($popover.data('bs.popover'), undefined, 'should not initialize the popover') + }) + }) diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index c2e2b937bea2..2875eff85ee6 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -1168,4 +1168,16 @@ $(function () { }, new Error('`selector` option must be specified when initializing tooltip on the window.document object!')) }) + QUnit.test('should do nothing when an attempt is made to hide an uninitialized tooltip', function (assert) { + assert.expect(1) + + var $tooltip = $('some text') + .appendTo('#qunit-fixture') + .on('hidden.bs.tooltip shown.bs.tooltip', function () { + assert.ok(false, 'should not fire any tooltip events') + }) + .bootstrapTooltip('hide') + assert.strictEqual($tooltip.data('bs.tooltip'), undefined, 'should not initialize the tooltip') + }) + }) diff --git a/js/tooltip.js b/js/tooltip.js index 6d7f6ccbe7c6..694cad5330ca 100644 --- a/js/tooltip.js +++ b/js/tooltip.js @@ -453,7 +453,7 @@ var data = $this.data('bs.tooltip') var options = typeof option == 'object' && option - if (!data && option == 'destroy') return + if (!data && (option == 'destroy' || option == 'hide')) return if (!data) $this.data('bs.tooltip', (data = new Tooltip(this, options))) if (typeof option == 'string') data[option]() })