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

@lookfirst

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

references issue #3880

@travisbot

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

@lookfirst

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.

@travisbot

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

@fat
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!

@fat fat closed this
@lookfirst

@fat umm... I did include tests.

@fat fat reopened this
@fat
Admin

weird, sorry about that

@travisbot

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.

@fat 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
@fat
Admin

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

@travisbot

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

@lookfirst

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?

@fat
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)

@lookfirst

ok, i'll hardcode it then.

@fat
Admin

cool thanks :)

@lookfirst

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...

@fat
Admin

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

@travisbot

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

@lookfirst

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

@fat fat merged commit 48fc0ad into from
@fat
Admin

great - thanks man!

@cvrebert 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. @lookfirst
Commits on Jul 20, 2012
  1. @lookfirst
Commits on Jul 22, 2012
  1. @lookfirst
  2. @lookfirst

    remove the ns option

    lookfirst authored
This page is out of date. Refresh to see the latest.
View
4 docs/templates/pages/javascript.mustache
@@ -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>
View
2  js/bootstrap-popover.js
@@ -72,7 +72,7 @@
}
, destroy: function () {
- this.$element.off().removeData('popover')
+ this.hide().$element.off('.' + this.type).removeData(this.type)
}
})
View
8 js/bootstrap-tooltip.js
@@ -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)
}
}
View
8 js/tests/unit/bootstrap-popover.js
@@ -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')
})
})
View
8 js/tests/unit/bootstrap-tooltip.js
@@ -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.