From f6a258ef36c0e9383b35e8f33cda14ba4718e0f3 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Sat, 5 Nov 2011 10:50:08 +1100 Subject: [PATCH 1/3] optionable selectors for title & content elements --- js/bootstrap-popover.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/js/bootstrap-popover.js b/js/bootstrap-popover.js index cf6dadf0a5..128bc54127 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' } @@ -81,6 +81,8 @@ $.fn.popover.defaults = $.extend({} , $.fn.twipsy.defaults, { placement: 'right' , template: '

' + , titleSelector: '.title' + , contentSelector: '.content p' }) -}( window.jQuery || window.ender ); \ No newline at end of file +}( window.jQuery || window.ender ); From 4d2e32e80914dbc526dcde7c743b0537ded7c853 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Sun, 6 Nov 2011 13:20:09 +1100 Subject: [PATCH 2/3] tests & docs & twipsy too --- docs/javascript.html | 30 ++++++++++++++++++++++++------ js/bootstrap-twipsy.js | 5 +++-- js/tests/unit/bootstrap-popover.js | 25 ++++++++++++++++++++++++- js/tests/unit/bootstrap-twipsy.js | 20 +++++++++++++++++++- 4 files changed, 70 insertions(+), 10 deletions(-) diff --git a/docs/javascript.html b/docs/javascript.html index 82dcffba75..90b7be0c53 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,13 @@ $('#.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 + + + contentSelector + string + .twipsy-inner + selector used to find the title element within the tooltip @@ -613,8 +619,8 @@ $('#.tabs').bind('change', function (e) { Name - type - default + type + default description @@ -689,7 +695,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-twipsy.js b/js/bootstrap-twipsy.js index e249c815d7..9eb6e79f4e 100644 --- a/js/bootstrap-twipsy.js +++ b/js/bootstrap-twipsy.js @@ -119,7 +119,7 @@ , setContent: function () { var $tip = this.tip() - $tip.find('.twipsy-inner')[this.options.html ? 'html' : 'text'](this.getTitle()) + $tip.find(this.options.contentSelector)[this.options.html ? 'html' : 'text'](this.getTitle()) $tip[0].className = 'twipsy' } @@ -302,10 +302,11 @@ , title: 'title' , trigger: 'hover' , template: '
' + , contentSelector: '.twipsy-inner' } $.fn.twipsy.elementOptions = function(ele, options) { return $.extend({}, options, $(ele).data()) } -}( 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..69f3e0d7fa 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) + .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() + }) + +}) diff --git a/js/tests/unit/bootstrap-twipsy.js b/js/tests/unit/bootstrap-twipsy.js index 04000696ae..74855931a6 100644 --- a/js/tests/unit/bootstrap-twipsy.js +++ b/js/tests/unit/bootstrap-twipsy.js @@ -78,4 +78,22 @@ $(function () { $('#qunit-runoff').empty() }) -}) \ No newline at end of file + test("should allow arbitrary template html with content selector options", function() { + $.support.transition = false + var twipsy = $('') + .appendTo('#qunit-runoff') + .twipsy({ + html: true + , contentSelector: 'h1' + , template: '

Funky Twipsy!

@rvagg was here

' + }) + .twipsy('show') + + ok($('.twipsy h1').length, 'h1 tag was inserted') + ok($('.twipsy p>b').length, 'p > b tags were inserted') + ok($('.twipsy h1>b').length, 'h1 tag was customised') + twipsy.twipsy('hide') + ok(!$(".twipsy").length, 'twipsy removed') + $('#qunit-runoff').empty() + }) +}) From 1b43c87eafc8948c517770282a63227cd9c5d792 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Mon, 7 Nov 2011 12:10:53 +1100 Subject: [PATCH 3/3] removed twipsy options --- docs/javascript.html | 6 ------ js/bootstrap-twipsy.js | 5 ++--- js/tests/unit/bootstrap-popover.js | 2 +- js/tests/unit/bootstrap-twipsy.js | 20 +------------------- 4 files changed, 4 insertions(+), 29 deletions(-) diff --git a/docs/javascript.html b/docs/javascript.html index d62dd731c1..4947735123 100644 --- a/docs/javascript.html +++ b/docs/javascript.html @@ -559,12 +559,6 @@ $('#.tabs').bind('change', function (e) { [default markup] the html template used for rendering a twipsy - - contentSelector - string - .twipsy-inner - selector used to find the title element within the tooltip -

Notice Individual twipsy instance options can alternatively be specified through the use of data attributes.

diff --git a/js/bootstrap-twipsy.js b/js/bootstrap-twipsy.js index 24c1ced8c7..5ebbddd675 100644 --- a/js/bootstrap-twipsy.js +++ b/js/bootstrap-twipsy.js @@ -119,7 +119,7 @@ , setContent: function () { var $tip = this.tip() - $tip.find(this.options.contentSelector)[this.options.html ? 'html' : 'text'](this.getTitle()) + $tip.find('.twipsy-inner')[this.options.html ? 'html' : 'text'](this.getTitle()) $tip[0].className = 'twipsy' } @@ -302,7 +302,6 @@ , title: 'title' , trigger: 'hover' , template: '
' - , contentSelector: '.twipsy-inner' } $.fn.twipsy.rejectAttrOptions = [ 'title' ] @@ -319,4 +318,4 @@ return $.extend({}, options, data) } -}( window.jQuery || window.ender ); +}( window.jQuery || window.ender ); \ No newline at end of file diff --git a/js/tests/unit/bootstrap-popover.js b/js/tests/unit/bootstrap-popover.js index 69f3e0d7fa..823526727f 100644 --- a/js/tests/unit/bootstrap-popover.js +++ b/js/tests/unit/bootstrap-popover.js @@ -78,7 +78,7 @@ $(function () { var expectedTitle = 'Gotta make you understand' , popover = $('@rvagg') .attr('title', expectedTitle) - .data('content', '

Never gonna give you up,

Never gonna let you down

') + .attr('data-content', '

Never gonna give you up,

Never gonna let you down

') .appendTo('#qunit-runoff') .popover({ html: true diff --git a/js/tests/unit/bootstrap-twipsy.js b/js/tests/unit/bootstrap-twipsy.js index 74855931a6..04000696ae 100644 --- a/js/tests/unit/bootstrap-twipsy.js +++ b/js/tests/unit/bootstrap-twipsy.js @@ -78,22 +78,4 @@ $(function () { $('#qunit-runoff').empty() }) - test("should allow arbitrary template html with content selector options", function() { - $.support.transition = false - var twipsy = $('') - .appendTo('#qunit-runoff') - .twipsy({ - html: true - , contentSelector: 'h1' - , template: '

Funky Twipsy!

@rvagg was here

' - }) - .twipsy('show') - - ok($('.twipsy h1').length, 'h1 tag was inserted') - ok($('.twipsy p>b').length, 'p > b tags were inserted') - ok($('.twipsy h1>b').length, 'h1 tag was customised') - twipsy.twipsy('hide') - ok(!$(".twipsy").length, 'twipsy removed') - $('#qunit-runoff').empty() - }) -}) +}) \ No newline at end of file