0
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-01-30 22:52:24 +01:00

Merge pull request #4104 from lookfirst/2.1.0-wip-fix-destroy

namespace the events for popover/tooltip
This commit is contained in:
♒∆✝ 2012-07-22 14:40:09 -07:00
commit 48fc0ad569
5 changed files with 20 additions and 10 deletions

View File

@ -780,7 +780,7 @@ $('a[data-toggle="tab"]').on('shown', function (e) {
<p>{{_i}}Toggles an element's tooltip.{{/i}}</p> <p>{{_i}}Toggles an element's tooltip.{{/i}}</p>
<pre class="prettyprint linenums">$('#element').tooltip('toggle')</pre> <pre class="prettyprint linenums">$('#element').tooltip('toggle')</pre>
<h4>.tooltip('destroy')</h4> <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> <pre class="prettyprint linenums">$('#element').tooltip('destroy')</pre>
</section> </section>
@ -935,7 +935,7 @@ $('a[data-toggle="tab"]').on('shown', function (e) {
<p>{{_i}}Toggles an elements popover.{{/i}}</p> <p>{{_i}}Toggles an elements popover.{{/i}}</p>
<pre class="prettyprint linenums">$('#element').popover('toggle')</pre> <pre class="prettyprint linenums">$('#element').popover('toggle')</pre>
<h4>.popover('destroy')</h4> <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> <pre class="prettyprint linenums">$('#element').popover('destroy')</pre>
</section> </section>

View File

@ -72,7 +72,7 @@
} }
, destroy: function () { , destroy: function () {
this.$element.off().removeData('popover') this.hide().$element.off('.' + this.type).removeData(this.type)
} }
}) })

View File

@ -47,8 +47,8 @@
if (this.options.trigger != 'manual') { if (this.options.trigger != 'manual') {
eventIn = this.options.trigger == 'hover' ? 'mouseenter' : 'focus' eventIn = this.options.trigger == 'hover' ? 'mouseenter' : 'focus'
eventOut = this.options.trigger == 'hover' ? 'mouseleave' : 'blur' eventOut = this.options.trigger == 'hover' ? 'mouseleave' : 'blur'
this.$element.on(eventIn, this.options.selector, $.proxy(this.enter, this)) this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this))
this.$element.on(eventOut, this.options.selector, $.proxy(this.leave, this)) this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this))
} }
this.options.selector ? this.options.selector ?
@ -176,6 +176,8 @@
$.support.transition && this.$tip.hasClass('fade') ? $.support.transition && this.$tip.hasClass('fade') ?
removeWithAnimation() : removeWithAnimation() :
$tip.remove() $tip.remove()
return this
} }
, fixTitle: function () { , fixTitle: function () {
@ -236,7 +238,7 @@
} }
, destroy: function () { , destroy: function () {
this.$element.off().removeData('tooltip') this.hide().$element.off('.' + this.type).removeData(this.type)
} }
} }

View File

@ -92,12 +92,16 @@ $(function () {
}) })
test("should destroy popover", 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('popover'), 'popover has data')
ok(popover.data('events').mouseover && popover.data('events').mouseout, 'popover has hover event') 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') popover.popover('destroy')
ok(!popover.hasClass('in'), 'popover is hidden')
ok(!popover.data('popover'), 'popover does not have data') 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 File

@ -129,12 +129,16 @@ $(function () {
}) })
test("should destroy tooltip", 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('tooltip'), 'tooltip has data')
ok(tooltip.data('events').mouseover && tooltip.data('events').mouseout, 'tooltip has hover event') 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') tooltip.tooltip('destroy')
ok(!tooltip.hasClass('in'), 'tooltip is hidden')
ok(!tooltip.data('tooltip'), 'tooltip does not have data') 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')
}) })
}) })