Skip to content

Commit

Permalink
Merge branch 'v4-dev' into v4-dev-johann-update-babel
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Nov 7, 2017
2 parents 2f7d276 + 26dc17b commit 7d9761e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
10 changes: 6 additions & 4 deletions js/src/popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ const Popover = (($) => {

// we use append for html objects to maintain js events
this.setElementContent($tip.find(Selector.TITLE), this.getTitle())
this.setElementContent($tip.find(Selector.CONTENT), this._getContent())
let content = this._getContent()
if (typeof content === 'function') {
content = content.call(this.element)
}
this.setElementContent($tip.find(Selector.CONTENT), content)

$tip.removeClass(`${ClassName.FADE} ${ClassName.SHOW}`)
}
Expand All @@ -133,9 +137,7 @@ const Popover = (($) => {

_getContent() {
return this.element.getAttribute('data-content')
|| (typeof this.config.content === 'function' ?
this.config.content.call(this.element) :
this.config.content)
|| this.config.content
}

_cleanTipClass() {
Expand Down
21 changes: 21 additions & 0 deletions js/tests/unit/popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,4 +410,25 @@ $(function () {
$popover.trigger($.Event('click'))
}, 200)
})

QUnit.test('popover should call content function only once', function (assert) {
assert.expect(1)
var done = assert.async()
var nbCall = 0
$('<div id="popover" style="display:none">content</div>').appendTo('#qunit-fixture')
var $popover = $('<a href="#">@Johann-S</a>')
.appendTo('#qunit-fixture')
.bootstrapPopover({
content: function () {
nbCall++
return $('#popover').clone().show().get(0)
}
})
.on('shown.bs.popover', function () {
assert.strictEqual(nbCall, 1)
done()
})

$popover.trigger($.Event('click'))
})
})

0 comments on commit 7d9761e

Please sign in to comment.