diff --git a/js/popover.js b/js/popover.js index 09be24433bff5d06058cdbd40d87a514fdac77dc..479d059c58397680f8c50c02dbb7538168c07080 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 && /destroy|hide/.test(option)) 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 ce89c8dbd661a52b70079ab8f97f395d7807f8ae..73a67c98406a65845f10c6083b813c9c65de4a5a 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 = $('<span data-toggle="popover" data-title="some title" data-content="some content">some text</span>') + .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 c2e2b937bea2859be6d33225087292b57f5bd998..2875eff85ee66e46b89c7eebe5bb49ee1be0f95e 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 = $('<span data-toggle="tooltip" title="some tip">some text</span>') + .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 6d7f6ccbe7c66c02003ed63a9c5b95899e55d88c..624ade71c364bb31a42f72c2804ec6edfea55d57 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 && /destroy|hide/.test(option)) return if (!data) $this.data('bs.tooltip', (data = new Tooltip(this, options))) if (typeof option == 'string') data[option]() })