diff --git a/docs/javascript.html b/docs/javascript.html index 6d67010705..4947735123 100644 --- a/docs/javascript.html +++ b/docs/javascript.html @@ -487,8 +487,8 @@ $('#.tabs').bind('change', function (e) { Name - type - default + type + default description @@ -557,7 +557,7 @@ $('#.tabs').bind('change', function (e) { template string [default markup] - The html template used for rendering a twipsy. + the html template used for rendering a twipsy @@ -613,8 +613,8 @@ $('#.tabs').bind('change', function (e) { Name - type - default + type + default description @@ -689,7 +689,19 @@ $('#.tabs').bind('change', function (e) { template string [default markup] - The html template used for rendering a popover. + the html template used for rendering a popover + + + titleSelector + string + .title + selector used to find the title element within the popover + + + contentSelector + string + .content p + selector used to find the content element within the popover diff --git a/js/bootstrap-popover.js b/js/bootstrap-popover.js index c637784157..e8b49af3c2 100644 --- a/js/bootstrap-popover.js +++ b/js/bootstrap-popover.js @@ -36,8 +36,8 @@ setContent: function () { var $tip = this.tip() - $tip.find('.title')[this.options.html ? 'html' : 'text'](this.getTitle()) - $tip.find('.content p')[this.options.html ? 'html' : 'text'](this.getContent()) + $tip.find(this.options.titleSelector)[this.options.html ? 'html' : 'text'](this.getTitle()) + $tip.find(this.options.contentSelector)[this.options.html ? 'html' : 'text'](this.getContent()) $tip[0].className = 'popover' } @@ -83,8 +83,10 @@ placement: 'right' , content: 'data-content' , template: '

' + , titleSelector: '.title' + , contentSelector: '.content p' }) $.fn.twipsy.rejectAttrOptions.push( 'content' ) -}( window.jQuery || window.ender ); \ No newline at end of file +}( window.jQuery || window.ender ); diff --git a/js/tests/unit/bootstrap-popover.js b/js/tests/unit/bootstrap-popover.js index 3e13d2fd20..823526727f 100644 --- a/js/tests/unit/bootstrap-popover.js +++ b/js/tests/unit/bootstrap-popover.js @@ -73,4 +73,27 @@ $(function () { $('#qunit-runoff').empty() }) -}) \ No newline at end of file + test("should allow arbitrary template html with title and content selector options", function() { + $.support.transition = false + var expectedTitle = 'Gotta make you understand' + , popover = $('@rvagg') + .attr('title', expectedTitle) + .attr('data-content', '

Never gonna give you up,

Never gonna let you down

') + .appendTo('#qunit-runoff') + .popover({ + html: true + , titleSelector: 'h1' + , contentSelector: '.rick > .roll' + , template: '

' + }) + .popover('show') + + ok($('.popover > div > h1').length, 'h1 tag was inserted') + ok($('.popover > div > h1').text() === expectedTitle) + ok($('.popover > .rick > .roll > p').length === 2, 'p > b tags were inserted') + popover.popover('hide') + ok(!$('.popover').length, 'popover was removed') + $('#qunit-runoff').empty() + }) + +})