Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

namespace the events for popover/tooltip #4104

Merged
merged 4 commits into from

3 participants

Jon Stevens Don't Add Me To Your Organization a.k.a The Travis Bot F A T
Jon Stevens

namespace the events for popover/tooltip so that they can be cleanly removed.

references issue #3880

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 2ee9b27 into 40ab928).

Jon Stevens

I wasn't sure what you wanted for the config key name... ns seemed short and sweet, but i'm open to changing it however you want.

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 117f65d into 40ab928).

F A T
Admin

Hey @lookfirst,

Thanks for opening this pull-request! Unfotunately, it looks like it fails to pass the tests neccessary for submitting to bootstrap. The following tests are currently failing:

  • should always include a unit test if changing js files

For a full list of issue filing guidelines, please refer to the bootstrap issue filing guidelines.

thanks!

F A T fat closed this
Jon Stevens

@fat umm... I did include tests.

F A T fat reopened this
F A T
Admin

weird, sorry about that

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 117f65d into 40ab928).

js/bootstrap-popover.js
@@ -72,7 +72,8 @@
}
, destroy: function () {
- this.$element.off().removeData('popover')
+ this.hide()
+ this.$element.off(this.options.ns).removeData('popover')

just realized that this could be combined into this.hide().off(this.options.ns)... if you like.

F A T Admin
fat added a note

yes pls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
F A T
Admin

any reason not to just always use the prefix .tooltip and .popover? Not super crazy about adding an option for that

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 393f4a7 into 40ab928).

Jon Stevens

i'm not super crazy about the option either, but i could easily see a generic word like those being used by other plugins.

how about something a bit less generic like bs-popover/bs-tooltip?

F A T
Admin

well... everywhere else we just use "modal" or "button". I don't think it's too big of a deal. If you have two different tooltip plugins instantiated on the same element you probably have bigger problems ;)

In the future we'll probably namespace everything with bootstrap (data-attrs and events - but that will be a 3.0.0 thing, because it's breaks backwards compatibility)

Jon Stevens

ok, i'll hardcode it then.

F A T
Admin

cool thanks :)

Jon Stevens

Oh, looking at that more closely now, I know why I did that... popover extends tooltip and tooltip.init() is where the .on() is... I needed to define the name of the plugin somewhere...

F A T
Admin

this.type will equal 'popover' or 'tooltip' - it's assigned in the init method

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged d76c899 into 40ab928).

Jon Stevens

ah, missed that. should be good now. all tests pass.

F A T fat merged commit 48fc0ad into from
F A T
Admin

great - thanks man!

Chris Rebert cvrebert locked and limited conversation to collaborators
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Commits on Jul 17, 2012
  1. Jon Stevens
Commits on Jul 20, 2012
  1. Jon Stevens
Commits on Jul 23, 2012
  1. Jon Stevens
  2. Jon Stevens

    remove the ns option

    lookfirst authored
This page is out of date. Refresh to see the latest.
4 docs/templates/pages/javascript.mustache
View
@@ -780,7 +780,7 @@ $('a[data-toggle="tab"]').on('shown', function (e) {
<p>{{_i}}Toggles an element's tooltip.{{/i}}</p>
<pre class="prettyprint linenums">$('#element').tooltip('toggle')</pre>
<h4>.tooltip('destroy')</h4>
- <p>{{_i}}Destroys an element's tooltip.{{/i}}</p>
+ <p>{{_i}}Hides and destroys an element's tooltip.{{/i}}</p>
<pre class="prettyprint linenums">$('#element').tooltip('destroy')</pre>
</section>
@@ -935,7 +935,7 @@ $('a[data-toggle="tab"]').on('shown', function (e) {
<p>{{_i}}Toggles an elements popover.{{/i}}</p>
<pre class="prettyprint linenums">$('#element').popover('toggle')</pre>
<h4>.popover('destroy')</h4>
- <p>{{_i}}Destroys an element's popover.{{/i}}</p>
+ <p>{{_i}}Hides and destroys an element's popover.{{/i}}</p>
<pre class="prettyprint linenums">$('#element').popover('destroy')</pre>
</section>
2  js/bootstrap-popover.js
View
@@ -72,7 +72,7 @@
}
, destroy: function () {
- this.$element.off().removeData('popover')
+ this.hide().$element.off('.' + this.type).removeData(this.type)
}
})
8 js/bootstrap-tooltip.js
View
@@ -47,8 +47,8 @@
if (this.options.trigger != 'manual') {
eventIn = this.options.trigger == 'hover' ? 'mouseenter' : 'focus'
eventOut = this.options.trigger == 'hover' ? 'mouseleave' : 'blur'
- this.$element.on(eventIn, this.options.selector, $.proxy(this.enter, this))
- this.$element.on(eventOut, this.options.selector, $.proxy(this.leave, this))
+ 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.options.selector ?
@@ -176,6 +176,8 @@
$.support.transition && this.$tip.hasClass('fade') ?
removeWithAnimation() :
$tip.remove()
+
+ return this
}
, fixTitle: function () {
@@ -236,7 +238,7 @@
}
, destroy: function () {
- this.$element.off().removeData('tooltip')
+ this.hide().$element.off('.' + this.type).removeData(this.type)
}
}
8 js/tests/unit/bootstrap-popover.js
View
@@ -92,12 +92,16 @@ $(function () {
})
test("should destroy popover", function () {
- var popover = $('<div/>').popover()
+ var popover = $('<div/>').popover().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')
+ popover.popover('show')
popover.popover('destroy')
+ ok(!popover.hasClass('in'), 'popover is hidden')
ok(!popover.data('popover'), 'popover does not have data')
- ok(!popover.data('events'), 'popover does not have any events')
+ ok(popover.data('events').click[0].namespace == 'foo', 'popover still has click.foo')
+ ok(!popover.data('events').mouseover && !popover.data('events').mouseout, 'popover does not have any events')
})
})
8 js/tests/unit/bootstrap-tooltip.js
View
@@ -129,12 +129,16 @@ $(function () {
})
test("should destroy tooltip", function () {
- var tooltip = $('<div/>').tooltip()
+ var tooltip = $('<div/>').tooltip().on('click.foo', function(){})
ok(tooltip.data('tooltip'), 'tooltip has data')
ok(tooltip.data('events').mouseover && tooltip.data('events').mouseout, 'tooltip has hover event')
+ ok(tooltip.data('events').click[0].namespace == 'foo', 'tooltip has extra click.foo event')
+ tooltip.tooltip('show')
tooltip.tooltip('destroy')
+ ok(!tooltip.hasClass('in'), 'tooltip is hidden')
ok(!tooltip.data('tooltip'), 'tooltip does not have data')
- ok(!tooltip.data('events'), 'tooltip does not have any events')
+ ok(tooltip.data('events').click[0].namespace == 'foo', 'tooltip still has click.foo')
+ ok(!tooltip.data('events').mouseover && !tooltip.data('events').mouseout, 'tooltip does not have any events')
})
})
Something went wrong with that request. Please try again.