diff options
| author | Chris Rebert <[email protected]> | 2015-03-04 01:40:01 -0800 |
|---|---|---|
| committer | Chris Rebert <[email protected]> | 2015-03-04 01:40:01 -0800 |
| commit | 3c190908ca6d1bcc762bb22f7719fc951b51166f (patch) | |
| tree | 5ef9b4e2c4c5b6d588e94939fcf56ba48362852b | |
| parent | 2f17289ab6665620c52a4a69750294f892a42e81 (diff) | |
| parent | 27bbc7dbe93799730112cb786a859331ca193130 (diff) | |
| download | bootstrap-3c190908ca6d1bcc762bb22f7719fc951b51166f.tar.xz bootstrap-3c190908ca6d1bcc762bb22f7719fc951b51166f.zip | |
Merge pull request #15988 from twbs/fix-15874
Hiding an uninitialized tooltip/popover no longer initializes it
| -rw-r--r-- | js/popover.js | 2 | ||||
| -rw-r--r-- | js/tests/unit/popover.js | 12 | ||||
| -rw-r--r-- | js/tests/unit/tooltip.js | 12 | ||||
| -rw-r--r-- | js/tooltip.js | 2 |
4 files changed, 26 insertions, 2 deletions
diff --git a/js/popover.js b/js/popover.js index 09be24433..479d059c5 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 ce89c8dbd..73a67c984 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 c2e2b937b..2875eff85 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 6d7f6ccbe..624ade71c 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]() }) |
