diff --git a/js/popover.js b/js/popover.js index 23aa82987..9cf9f7113 100644 --- a/js/popover.js +++ b/js/popover.js @@ -44,7 +44,7 @@ var content = this.getContent() $tip.find('.popover-title')[this.options.html ? 'html' : 'text'](title) - $tip.find('.popover-content')[ // we use append for html objects to maintain js events + $tip.find('.popover-content').empty()[ // we use append for html objects to maintain js events this.options.html ? (typeof content == 'string' ? 'html' : 'append') : 'text' ](content) diff --git a/js/tests/unit/popover.js b/js/tests/unit/popover.js index c08b6d8ef..24f2f6f03 100644 --- a/js/tests/unit/popover.js +++ b/js/tests/unit/popover.js @@ -61,6 +61,35 @@ $(function () { $('#qunit-fixture').empty() }) + test('should not duplicate HTML object', function () { + $.support.transition = false + + $div = $('
').html('loves writing tests (╯°□°)╯︵ ┻━┻') + + var popover = $('@fat') + .appendTo('#qunit-fixture') + .popover({ + content: function () { + return $div + } + }) + + popover.popover('show') + ok($('.popover').length, 'popover was inserted') + equal($('.popover .popover-content').html(), $div, 'content correctly inserted') + + popover.popover('hide') + ok(!$('.popover').length, 'popover was removed') + + popover.popover('show') + ok($('.popover').length, 'popover was inserted') + equal($('.popover .popover-content').html(), $div, 'content correctly inserted') + + popover.popover('hide') + ok(!$('.popover').length, 'popover was removed') + $('#qunit-fixture').empty() + }) + test('should get title and content from attributes', function () { $.support.transition = false var popover = $('@mdo')