add click option for tooltip, popover - make click default for popover

This commit is contained in:
Jacob Thornton 2012-08-18 19:54:30 -07:00
parent 44e35e9dfa
commit 45dddc59a1
9 changed files with 26 additions and 17 deletions

View File

@ -95,6 +95,7 @@
$.fn.popover.defaults = $.extend({} , $.fn.tooltip.defaults, {
placement: 'right'
, trigger: 'click'
, content: ''
, template: '<div class="popover"><div class="arrow"></div><div class="popover-inner"><h3 class="popover-title"></h3><div class="popover-content"><p></p></div></div></div>'
})

View File

@ -44,8 +44,10 @@
this.options = this.getOptions(options)
this.enabled = true
if (this.options.trigger != 'manual') {
eventIn = this.options.trigger == 'hover' ? 'mouseenter' : 'focus'
if (this.options.trigger == 'click') {
this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this))
} else if (this.options.trigger != 'manual') {
eventIn = this.options.trigger == 'hover' ? 'mouseenter' : 'focus'
eventOut = this.options.trigger == 'hover' ? 'mouseleave' : 'blur'
this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this))
this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this))

View File

@ -1006,8 +1006,10 @@
this.options = this.getOptions(options)
this.enabled = true
if (this.options.trigger != 'manual') {
eventIn = this.options.trigger == 'hover' ? 'mouseenter' : 'focus'
if (this.options.trigger == 'click') {
this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this))
} else if (this.options.trigger != 'manual') {
eventIn = this.options.trigger == 'hover' ? 'mouseenter' : 'focus'
eventOut = this.options.trigger == 'hover' ? 'mouseleave' : 'blur'
this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this))
this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this))
@ -1330,6 +1332,7 @@
$.fn.popover.defaults = $.extend({} , $.fn.tooltip.defaults, {
placement: 'right'
, trigger: 'click'
, content: ''
, template: '<div class="popover"><div class="arrow"></div><div class="popover-inner"><h3 class="popover-title"></h3><div class="popover-content"><p></p></div></div></div>'
})

File diff suppressed because one or more lines are too long

View File

@ -566,7 +566,7 @@ $('#myModal').on('hidden', function () {
<h2>Usage</h2>
<h3>Via data attributes</h3>
<p>To easily add scrollspy behavior to your topbar navigation, just add <code>data-spy="scroll"</code> to the element you want to spy on (most typically this would be the body) and <code>data-target=".navbar"</code> to select which nav to use. You'll want to scrollspy with the <code>.nav</code> class.</p>
<p>To easily add scrollspy behavior to your topbar navigation, just add <code>data-spy="scroll"</code> to the element you want to spy on (most typically this would be the body) and <code>data-target=".navbar"</code> to select which nav to use. You'll want to use scrollspy with a <code>.nav</code> component.</p>
<pre class="prettyprint linenums">&lt;body data-spy="scroll" data-target=".navbar"&gt;...&lt;/body&gt;</pre>
<h3>Via JavaScript</h3>
@ -829,7 +829,7 @@ $('a[data-toggle="tab"]').on('shown', function (e) {
<td>trigger</td>
<td>string</td>
<td>'hover'</td>
<td>how tooltip is triggered - hover | focus | manual</td>
<td>how tooltip is triggered - click | hover | focus | manual</td>
</tr>
<tr>
<td>delay</td>
@ -922,7 +922,7 @@ $('a[data-toggle="tab"]').on('shown', function (e) {
<h3>Live demo</h3>
<div class="bs-docs-example" style="padding-bottom: 24px;">
<a href="#" class="btn btn-large btn-danger" rel="popover" title="A Title" data-content="And here's some amazing content. It's very engaging. right?">Hover for popover</a>
<a href="#" class="btn btn-large btn-danger" rel="popover" title="A Title" data-content="And here's some amazing content. It's very engaging. right?">Click to toggle popover</a>
</div>
@ -972,8 +972,8 @@ $('a[data-toggle="tab"]').on('shown', function (e) {
<tr>
<td>trigger</td>
<td>string</td>
<td>'hover'</td>
<td>how popover is triggered - hover | focus | manual</td>
<td>'click'</td>
<td>how popover is triggered - click | hover | focus | manual</td>
</tr>
<tr>
<td>title</td>

View File

@ -759,7 +759,7 @@ $('a[data-toggle="tab"]').on('shown', function (e) {
<td>{{_i}}trigger{{/i}}</td>
<td>{{_i}}string{{/i}}</td>
<td>'hover'</td>
<td>{{_i}}how tooltip is triggered{{/i}} - hover | focus | manual</td>
<td>{{_i}}how tooltip is triggered{{/i}} - click | hover | focus | manual</td>
</tr>
<tr>
<td>{{_i}}delay{{/i}}</td>
@ -852,7 +852,7 @@ $('a[data-toggle="tab"]').on('shown', function (e) {
<h3>Live demo</h3>
<div class="bs-docs-example" style="padding-bottom: 24px;">
<a href="#" class="btn btn-large btn-danger" rel="popover" title="A Title" data-content="And here's some amazing content. It's very engaging. right?">{{_i}}Hover for popover{{/i}}</a>
<a href="#" class="btn btn-large btn-danger" rel="popover" title="A Title" data-content="And here's some amazing content. It's very engaging. right?">{{_i}}Click to toggle popover{{/i}}</a>
</div>
@ -902,8 +902,8 @@ $('a[data-toggle="tab"]').on('shown', function (e) {
<tr>
<td>{{_i}}trigger{{/i}}</td>
<td>{{_i}}string{{/i}}</td>
<td>'hover'</td>
<td>{{_i}}how popover is triggered{{/i}} - hover | focus | manual</td>
<td>'click'</td>
<td>{{_i}}how popover is triggered{{/i}} - click | hover | focus | manual</td>
</tr>
<tr>
<td>{{_i}}title{{/i}}</td>

View File

@ -95,6 +95,7 @@
$.fn.popover.defaults = $.extend({} , $.fn.tooltip.defaults, {
placement: 'right'
, trigger: 'click'
, content: ''
, template: '<div class="popover"><div class="arrow"></div><div class="popover-inner"><h3 class="popover-title"></h3><div class="popover-content"><p></p></div></div></div>'
})

View File

@ -44,8 +44,10 @@
this.options = this.getOptions(options)
this.enabled = true
if (this.options.trigger != 'manual') {
eventIn = this.options.trigger == 'hover' ? 'mouseenter' : 'focus'
if (this.options.trigger == 'click') {
this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this))
} else if (this.options.trigger != 'manual') {
eventIn = this.options.trigger == 'hover' ? 'mouseenter' : 'focus'
eventOut = this.options.trigger == 'hover' ? 'mouseleave' : 'blur'
this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this))
this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this))

View File

@ -92,7 +92,7 @@ $(function () {
})
test("should destroy popover", function () {
var popover = $('<div/>').popover().on('click.foo', function(){})
var popover = $('<div/>').popover({trigger: 'hover'}).on('click.foo', function(){})
ok(popover.data('popover'), 'popover has data')
ok(popover.data('events').mouseover && popover.data('events').mouseout, 'popover has hover event')
ok(popover.data('events').click[0].namespace == 'foo', 'popover has extra click.foo event')