Skip to content

Commit b37a336

Browse files
committed
Merge pull request twbs#554 from rvagg/poveropt
optionable selectors for title & content elements
2 parents b15e24e + 1b43c87 commit b37a336

File tree

3 files changed

+47
-10
lines changed

3 files changed

+47
-10
lines changed

docs/javascript.html

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,8 @@ <h3>Options</h3>
487487
<thead>
488488
<tr>
489489
<th style="width: 100px;">Name</th>
490-
<th style="width: 100px;">type</th>
491-
<th style="width: 50px;">default</th>
490+
<th style="width: 95px;">type</th>
491+
<th style="width: 95px;">default</th>
492492
<th>description</th>
493493
</tr>
494494
</thead>
@@ -557,7 +557,7 @@ <h3>Options</h3>
557557
<td>template</td>
558558
<td>string</td>
559559
<td>[default markup]</td>
560-
<td>The html template used for rendering a twipsy.</td>
560+
<td>the html template used for rendering a twipsy</td>
561561
</tr>
562562
</tbody>
563563
</table>
@@ -613,8 +613,8 @@ <h3>Options</h3>
613613
<thead>
614614
<tr>
615615
<th style="width: 100px;">Name</th>
616-
<th style="width: 100px;">type</th>
617-
<th style="width: 50px;">default</th>
616+
<th style="width: 95px;">type</th>
617+
<th style="width: 95px;">default</th>
618618
<th>description</th>
619619
</tr>
620620
</thead>
@@ -689,7 +689,19 @@ <h3>Options</h3>
689689
<td>template</td>
690690
<td>string</td>
691691
<td>[default markup]</td>
692-
<td>The html template used for rendering a popover.</td>
692+
<td>the html template used for rendering a popover</td>
693+
</tr>
694+
<tr>
695+
<td>titleSelector</td>
696+
<td>string</td>
697+
<td>.title</td>
698+
<td>selector used to find the title element within the popover</td>
699+
</tr>
700+
<tr>
701+
<td>contentSelector</td>
702+
<td>string</td>
703+
<td>.content p</td>
704+
<td>selector used to find the content element within the popover</td>
693705
</tr>
694706
</tbody>
695707
</table>

js/bootstrap-popover.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636

3737
setContent: function () {
3838
var $tip = this.tip()
39-
$tip.find('.title')[this.options.html ? 'html' : 'text'](this.getTitle())
40-
$tip.find('.content p')[this.options.html ? 'html' : 'text'](this.getContent())
39+
$tip.find(this.options.titleSelector)[this.options.html ? 'html' : 'text'](this.getTitle())
40+
$tip.find(this.options.contentSelector)[this.options.html ? 'html' : 'text'](this.getContent())
4141
$tip[0].className = 'popover'
4242
}
4343

@@ -83,8 +83,10 @@
8383
placement: 'right'
8484
, content: 'data-content'
8585
, template: '<div class="arrow"></div><div class="inner"><h3 class="title"></h3><div class="content"><p></p></div></div>'
86+
, titleSelector: '.title'
87+
, contentSelector: '.content p'
8688
})
8789

8890
$.fn.twipsy.rejectAttrOptions.push( 'content' )
8991

90-
}( window.jQuery || window.ender );
92+
}( window.jQuery || window.ender );

js/tests/unit/bootstrap-popover.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,27 @@ $(function () {
7373
$('#qunit-runoff').empty()
7474
})
7575

76-
})
76+
test("should allow arbitrary template html with title and content selector options", function() {
77+
$.support.transition = false
78+
var expectedTitle = 'Gotta make you understand'
79+
, popover = $('<a href="#">@rvagg</a>')
80+
.attr('title', expectedTitle)
81+
.attr('data-content', '<p><b>Never gonna give you up</b>,</p><p>Never gonna let you down</p>')
82+
.appendTo('#qunit-runoff')
83+
.popover({
84+
html: true
85+
, titleSelector: 'h1'
86+
, contentSelector: '.rick > .roll'
87+
, template: '<div class="rick"><h1></h1><div class="roll"></div></div>'
88+
})
89+
.popover('show')
90+
91+
ok($('.popover > div > h1').length, 'h1 tag was inserted')
92+
ok($('.popover > div > h1').text() === expectedTitle)
93+
ok($('.popover > .rick > .roll > p').length === 2, 'p > b tags were inserted')
94+
popover.popover('hide')
95+
ok(!$('.popover').length, 'popover was removed')
96+
$('#qunit-runoff').empty()
97+
})
98+
99+
})

0 commit comments

Comments
 (0)