Skip to content

Commit 4d2e32e

Browse files
committed
tests & docs & twipsy too
1 parent 3628eb7 commit 4d2e32e

File tree

4 files changed

+70
-10
lines changed

4 files changed

+70
-10
lines changed

docs/javascript.html

Lines changed: 24 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,13 @@ <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>
561+
</tr>
562+
<tr>
563+
<td>contentSelector</td>
564+
<td>string</td>
565+
<td>.twipsy-inner</td>
566+
<td>selector used to find the title element within the tooltip</td>
561567
</tr>
562568
</tbody>
563569
</table>
@@ -613,8 +619,8 @@ <h3>Options</h3>
613619
<thead>
614620
<tr>
615621
<th style="width: 100px;">Name</th>
616-
<th style="width: 100px;">type</th>
617-
<th style="width: 50px;">default</th>
622+
<th style="width: 95px;">type</th>
623+
<th style="width: 95px;">default</th>
618624
<th>description</th>
619625
</tr>
620626
</thead>
@@ -689,7 +695,19 @@ <h3>Options</h3>
689695
<td>template</td>
690696
<td>string</td>
691697
<td>[default markup]</td>
692-
<td>The html template used for rendering a popover.</td>
698+
<td>the html template used for rendering a popover</td>
699+
</tr>
700+
<tr>
701+
<td>titleSelector</td>
702+
<td>string</td>
703+
<td>.title</td>
704+
<td>selector used to find the title element within the popover</td>
705+
</tr>
706+
<tr>
707+
<td>contentSelector</td>
708+
<td>string</td>
709+
<td>.content p</td>
710+
<td>selector used to find the content element within the popover</td>
693711
</tr>
694712
</tbody>
695713
</table>

js/bootstrap-twipsy.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119

120120
, setContent: function () {
121121
var $tip = this.tip()
122-
$tip.find('.twipsy-inner')[this.options.html ? 'html' : 'text'](this.getTitle())
122+
$tip.find(this.options.contentSelector)[this.options.html ? 'html' : 'text'](this.getTitle())
123123
$tip[0].className = 'twipsy'
124124
}
125125

@@ -302,10 +302,11 @@
302302
, title: 'title'
303303
, trigger: 'hover'
304304
, template: '<div class="twipsy-arrow"></div><div class="twipsy-inner"></div>'
305+
, contentSelector: '.twipsy-inner'
305306
}
306307

307308
$.fn.twipsy.elementOptions = function(ele, options) {
308309
return $.extend({}, options, $(ele).data())
309310
}
310311

311-
}( window.jQuery || window.ender );
312+
}( 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+
.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+
})

js/tests/unit/bootstrap-twipsy.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,22 @@ $(function () {
7878
$('#qunit-runoff').empty()
7979
})
8080

81-
})
81+
test("should allow arbitrary template html with content selector options", function() {
82+
$.support.transition = false
83+
var twipsy = $('<a href="#" rel="twipsy" title="<b>@fat</b>"></a>')
84+
.appendTo('#qunit-runoff')
85+
.twipsy({
86+
html: true
87+
, contentSelector: 'h1'
88+
, template: '<div><h1>Funky Twipsy!</h1><p class="funky"><b>@rvagg was here</b></p></div>'
89+
})
90+
.twipsy('show')
91+
92+
ok($('.twipsy h1').length, 'h1 tag was inserted')
93+
ok($('.twipsy p>b').length, 'p > b tags were inserted')
94+
ok($('.twipsy h1>b').length, 'h1 tag was customised')
95+
twipsy.twipsy('hide')
96+
ok(!$(".twipsy").length, 'twipsy removed')
97+
$('#qunit-runoff').empty()
98+
})
99+
})

0 commit comments

Comments
 (0)