Commit 26dc17b 1 parent b42a38b commit 26dc17b Copy full SHA for 26dc17b
File tree 2 files changed +27
-4
lines changed
2 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -124,7 +124,11 @@ const Popover = (($) => {
124
124
125
125
// we use append for html objects to maintain js events
126
126
this . setElementContent ( $tip . find ( Selector . TITLE ) , this . getTitle ( ) )
127
- this . setElementContent ( $tip . find ( Selector . CONTENT ) , this . _getContent ( ) )
127
+ let content = this . _getContent ( )
128
+ if ( typeof content === 'function' ) {
129
+ content = content . call ( this . element )
130
+ }
131
+ this . setElementContent ( $tip . find ( Selector . CONTENT ) , content )
128
132
129
133
$tip . removeClass ( `${ ClassName . FADE } ${ ClassName . SHOW } ` )
130
134
}
@@ -133,9 +137,7 @@ const Popover = (($) => {
133
137
134
138
_getContent ( ) {
135
139
return this . element . getAttribute ( 'data-content' )
136
- || ( typeof this . config . content === 'function' ?
137
- this . config . content . call ( this . element ) :
138
- this . config . content )
140
+ || this . config . content
139
141
}
140
142
141
143
_cleanTipClass ( ) {
Original file line number Diff line number Diff line change @@ -410,4 +410,25 @@ $(function () {
410
410
$popover . trigger ( $ . Event ( 'click' ) )
411
411
} , 200 )
412
412
} )
413
+
414
+ QUnit . test ( 'popover should call content function only once' , function ( assert ) {
415
+ assert . expect ( 1 )
416
+ var done = assert . async ( )
417
+ var nbCall = 0
418
+ $ ( '<div id="popover" style="display:none">content</div>' ) . appendTo ( '#qunit-fixture' )
419
+ var $popover = $ ( '<a href="#">@Johann-S</a>' )
420
+ . appendTo ( '#qunit-fixture' )
421
+ . bootstrapPopover ( {
422
+ content : function ( ) {
423
+ nbCall ++
424
+ return $ ( '#popover' ) . clone ( ) . show ( ) . get ( 0 )
425
+ }
426
+ } )
427
+ . on ( 'shown.bs.popover' , function ( ) {
428
+ assert . strictEqual ( nbCall , 1 )
429
+ done ( )
430
+ } )
431
+
432
+ $popover . trigger ( $ . Event ( 'click' ) )
433
+ } )
413
434
} )
You can’t perform that action at this time.
0 commit comments