Skip to content

Commit

Permalink
Support multiple tooltip and popover trigger methods
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianheine committed Dec 2, 2012
1 parent ea61cdb commit eae3d22
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 35 deletions.
30 changes: 20 additions & 10 deletions docs/assets/js/bootstrap-tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,13 @@
constructor: Tooltip

, init: function (type, element, options) {
var eventIn
, eventOut

this.type = type
this.$element = $(element)
this.options = this.getOptions(options)
this.enabled = true

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))
}
this.bind();

this.options.selector ?
(this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) :
Expand All @@ -71,6 +62,25 @@
return options
}

, bind: function () {
var eventIn
, eventOut
, i
, trigger
, triggers = this.options.trigger.split(' ');
for (i = 0; i < triggers.length; ++i) {
trigger = triggers[i];
if (trigger == 'click') {
this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this))
} else if (trigger == 'hover' || trigger == 'focus') {
eventIn = trigger == 'hover' ? 'mouseenter' : 'focus'
eventOut = 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))
}
}
}

, enter: function (e) {
var self = $(e.currentTarget)[this.type](this._options).data(this.type)

Expand Down
30 changes: 20 additions & 10 deletions docs/assets/js/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -986,22 +986,13 @@
constructor: Tooltip

, init: function (type, element, options) {
var eventIn
, eventOut

this.type = type
this.$element = $(element)
this.options = this.getOptions(options)
this.enabled = true

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))
}
this.bind();

this.options.selector ?
(this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) :
Expand All @@ -1021,6 +1012,25 @@
return options
}

, bind: function () {
var eventIn
, eventOut
, i
, trigger
, triggers = this.options.trigger.split(' ');
for (i = 0; i < triggers.length; ++i) {
trigger = triggers[i];
if (trigger == 'click') {
this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this))
} else if (trigger == 'hover' || trigger == 'focus') {
eventIn = trigger == 'hover' ? 'mouseenter' : 'focus'
eventOut = 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))
}
}
}

, enter: function (e) {
var self = $(e.currentTarget)[this.type](this._options).data(this.type)

Expand Down
2 changes: 1 addition & 1 deletion docs/assets/js/bootstrap.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/javascript.html
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ <h3>Options</h3>
<td>trigger</td>
<td>string</td>
<td>'hover'</td>
<td>how tooltip is triggered - click | hover | focus | manual</td>
<td>how tooltip is triggered; multiple, space-separated values are possible. - click | hover | focus | manual</td>
</tr>
<tr>
<td>delay</td>
Expand Down Expand Up @@ -983,7 +983,7 @@ <h3>Options</h3>
<td>trigger</td>
<td>string</td>
<td>'click'</td>
<td>how popover is triggered - click | hover | focus | manual</td>
<td>how popover is triggered; multiple, space-separated values are possible. - click | hover | focus | manual</td>
</tr>
<tr>
<td>title</td>
Expand Down
4 changes: 2 additions & 2 deletions docs/templates/pages/javascript.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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}} - click | hover | focus | manual</td>
<td>{{_i}}how tooltip is triggered; multiple, space-separated values are possible.{{/i}} - click | hover | focus | manual</td>
</tr>
<tr>
<td>{{_i}}delay{{/i}}</td>
Expand Down Expand Up @@ -913,7 +913,7 @@ $('a[data-toggle="tab"]').on('shown', function (e) {
<td>{{_i}}trigger{{/i}}</td>
<td>{{_i}}string{{/i}}</td>
<td>'click'</td>
<td>{{_i}}how popover is triggered{{/i}} - click | hover | focus | manual</td>
<td>{{_i}}how popover is triggered; multiple, space-separated values are possible.{{/i}} - click | hover | focus | manual</td>
</tr>
<tr>
<td>{{_i}}title{{/i}}</td>
Expand Down
30 changes: 20 additions & 10 deletions js/bootstrap-tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,13 @@
constructor: Tooltip

, init: function (type, element, options) {
var eventIn
, eventOut

this.type = type
this.$element = $(element)
this.options = this.getOptions(options)
this.enabled = true

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))
}
this.bind();

this.options.selector ?
(this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) :
Expand All @@ -71,6 +62,25 @@
return options
}

, bind: function () {
var eventIn
, eventOut
, i
, trigger
, triggers = this.options.trigger.split(' ');
for (i = 0; i < triggers.length; ++i) {
trigger = triggers[i];
if (trigger == 'click') {
this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this))
} else if (trigger == 'hover' || trigger == 'focus') {
eventIn = trigger == 'hover' ? 'mouseenter' : 'focus'
eventOut = 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))
}
}
}

, enter: function (e) {
var self = $(e.currentTarget)[this.type](this._options).data(this.type)

Expand Down

0 comments on commit eae3d22

Please sign in to comment.