From 2ee9b2717bfd532e93eb6d4037ae7ca7a5436957 Mon Sep 17 00:00:00 2001 From: Jon Stevens Date: Mon, 16 Jul 2012 16:01:11 -0700 Subject: [PATCH 1/4] namespace the events for popover/tooltip so that they can be cleanly removed. issue #3880 --- docs/templates/pages/javascript.mustache | 12 ++++++++++++ js/bootstrap-popover.js | 3 ++- js/bootstrap-tooltip.js | 7 ++++--- js/tests/unit/bootstrap-popover.js | 6 ++++-- js/tests/unit/bootstrap-tooltip.js | 6 ++++-- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/docs/templates/pages/javascript.mustache b/docs/templates/pages/javascript.mustache index 81ef75209d..49d065c326 100644 --- a/docs/templates/pages/javascript.mustache +++ b/docs/templates/pages/javascript.mustache @@ -754,6 +754,12 @@ $('a[data-toggle="tab"]').on('shown', function (e) {

{{_i}}Object structure is: delay: { show: 500, hide: 100 }{{/i}}

+ + {{_i}}ns{{/i}} + {{_i}}string{{/i}} + '.tooltip' + {{_i}}jQuery event namespace{{/i}} +
@@ -912,6 +918,12 @@ $('a[data-toggle="tab"]').on('shown', function (e) {

{{_i}}Object structure is: delay: { show: 500, hide: 100 }{{/i}}

+ + {{_i}}ns{{/i}} + {{_i}}string{{/i}} + '.popover' + {{_i}}jQuery event namespace{{/i}} +
diff --git a/js/bootstrap-popover.js b/js/bootstrap-popover.js index fe22ecb47c..845108b9ba 100644 --- a/js/bootstrap-popover.js +++ b/js/bootstrap-popover.js @@ -72,7 +72,7 @@ } , destroy: function () { - this.$element.off().removeData('popover') + this.$element.off(this.options.ns).removeData('popover') } }) @@ -97,6 +97,7 @@ placement: 'right' , content: '' , template: '

' + , ns: '.popover' }) }(window.jQuery); \ No newline at end of file diff --git a/js/bootstrap-tooltip.js b/js/bootstrap-tooltip.js index f280e36966..02f84d470d 100644 --- a/js/bootstrap-tooltip.js +++ b/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.options.ns, this.options.selector, $.proxy(this.enter, this)) + this.$element.on(eventOut + this.options.ns, this.options.selector, $.proxy(this.leave, this)) } this.options.selector ? @@ -236,7 +236,7 @@ } , destroy: function () { - this.$element.off().removeData('tooltip') + this.$element.off(this.options.ns).removeData('tooltip') } } @@ -266,6 +266,7 @@ , title: '' , delay: 0 , html: true + , ns: '.tooltip' } }(window.jQuery); diff --git a/js/tests/unit/bootstrap-popover.js b/js/tests/unit/bootstrap-popover.js index 6d5d9f7a18..290be827ff 100644 --- a/js/tests/unit/bootstrap-popover.js +++ b/js/tests/unit/bootstrap-popover.js @@ -92,12 +92,14 @@ $(function () { }) test("should destroy popover", function () { - var popover = $('
').popover() + var popover = $('
').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('destroy') 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') }) }) \ No newline at end of file diff --git a/js/tests/unit/bootstrap-tooltip.js b/js/tests/unit/bootstrap-tooltip.js index 7852305c1e..66bbeac7ec 100644 --- a/js/tests/unit/bootstrap-tooltip.js +++ b/js/tests/unit/bootstrap-tooltip.js @@ -129,12 +129,14 @@ $(function () { }) test("should destroy tooltip", function () { - var tooltip = $('
').tooltip() + var tooltip = $('
').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('destroy') 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') }) }) From 117f65d43108d5d7ff1c5011f0b8b61f7ef3b9dd Mon Sep 17 00:00:00 2001 From: Jon Stevens Date: Fri, 20 Jul 2012 09:47:12 -0700 Subject: [PATCH 2/4] on destroy, also hide. issue #3880, pull #4104 --- docs/templates/pages/javascript.mustache | 4 ++-- js/bootstrap-popover.js | 1 + js/bootstrap-tooltip.js | 1 + js/tests/unit/bootstrap-popover.js | 2 ++ js/tests/unit/bootstrap-tooltip.js | 2 ++ 5 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/templates/pages/javascript.mustache b/docs/templates/pages/javascript.mustache index 49d065c326..4ec8a5f517 100644 --- a/docs/templates/pages/javascript.mustache +++ b/docs/templates/pages/javascript.mustache @@ -786,7 +786,7 @@ $('a[data-toggle="tab"]').on('shown', function (e) {

{{_i}}Toggles an element's tooltip.{{/i}}

$('#element').tooltip('toggle')

.tooltip('destroy')

-

{{_i}}Destroys an element's tooltip.{{/i}}

+

{{_i}}Hides and destroys an element's tooltip.{{/i}}

$('#element').tooltip('destroy')
@@ -947,7 +947,7 @@ $('a[data-toggle="tab"]').on('shown', function (e) {

{{_i}}Toggles an elements popover.{{/i}}

$('#element').popover('toggle')

.popover('destroy')

-

{{_i}}Destroys an element's popover.{{/i}}

+

{{_i}}Hides and destroys an element's popover.{{/i}}

$('#element').popover('destroy')
diff --git a/js/bootstrap-popover.js b/js/bootstrap-popover.js index 845108b9ba..57420bb5d9 100644 --- a/js/bootstrap-popover.js +++ b/js/bootstrap-popover.js @@ -72,6 +72,7 @@ } , destroy: function () { + this.hide() this.$element.off(this.options.ns).removeData('popover') } diff --git a/js/bootstrap-tooltip.js b/js/bootstrap-tooltip.js index 02f84d470d..f22aa8e643 100644 --- a/js/bootstrap-tooltip.js +++ b/js/bootstrap-tooltip.js @@ -236,6 +236,7 @@ } , destroy: function () { + this.hide() this.$element.off(this.options.ns).removeData('tooltip') } diff --git a/js/tests/unit/bootstrap-popover.js b/js/tests/unit/bootstrap-popover.js index 290be827ff..daffe215c9 100644 --- a/js/tests/unit/bootstrap-popover.js +++ b/js/tests/unit/bootstrap-popover.js @@ -96,7 +96,9 @@ $(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').click[0].namespace == 'foo', 'popover still has click.foo') ok(!popover.data('events').mouseover && !popover.data('events').mouseout, 'popover does not have any events') diff --git a/js/tests/unit/bootstrap-tooltip.js b/js/tests/unit/bootstrap-tooltip.js index 66bbeac7ec..2eb8c8f7c9 100644 --- a/js/tests/unit/bootstrap-tooltip.js +++ b/js/tests/unit/bootstrap-tooltip.js @@ -133,7 +133,9 @@ $(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').click[0].namespace == 'foo', 'tooltip still has click.foo') ok(!tooltip.data('events').mouseover && !tooltip.data('events').mouseout, 'tooltip does not have any events') From 393f4a7b4244233a6ad24a48b68869329f4756b8 Mon Sep 17 00:00:00 2001 From: Jon Stevens Date: Sun, 22 Jul 2012 14:19:11 -0700 Subject: [PATCH 3/4] simplify things to one line. pull #4104 --- js/bootstrap-popover.js | 3 +-- js/bootstrap-tooltip.js | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/js/bootstrap-popover.js b/js/bootstrap-popover.js index 57420bb5d9..2a2b298dca 100644 --- a/js/bootstrap-popover.js +++ b/js/bootstrap-popover.js @@ -72,8 +72,7 @@ } , destroy: function () { - this.hide() - this.$element.off(this.options.ns).removeData('popover') + this.hide().$element.off(this.options.ns).removeData('popover') } }) diff --git a/js/bootstrap-tooltip.js b/js/bootstrap-tooltip.js index f22aa8e643..fa1c9a6c53 100644 --- a/js/bootstrap-tooltip.js +++ b/js/bootstrap-tooltip.js @@ -176,6 +176,8 @@ $.support.transition && this.$tip.hasClass('fade') ? removeWithAnimation() : $tip.remove() + + return this } , fixTitle: function () { @@ -236,8 +238,7 @@ } , destroy: function () { - this.hide() - this.$element.off(this.options.ns).removeData('tooltip') + this.hide().$element.off(this.options.ns).removeData('tooltip') } } From d76c8991424b91050636fb94e740daa123306e95 Mon Sep 17 00:00:00 2001 From: Jon Stevens Date: Sun, 22 Jul 2012 14:36:23 -0700 Subject: [PATCH 4/4] remove the ns option --- docs/templates/pages/javascript.mustache | 12 ------------ js/bootstrap-popover.js | 3 +-- js/bootstrap-tooltip.js | 7 +++---- 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/docs/templates/pages/javascript.mustache b/docs/templates/pages/javascript.mustache index 4ec8a5f517..13480719e2 100644 --- a/docs/templates/pages/javascript.mustache +++ b/docs/templates/pages/javascript.mustache @@ -754,12 +754,6 @@ $('a[data-toggle="tab"]').on('shown', function (e) {

{{_i}}Object structure is: delay: { show: 500, hide: 100 }{{/i}}

- - {{_i}}ns{{/i}} - {{_i}}string{{/i}} - '.tooltip' - {{_i}}jQuery event namespace{{/i}} -
@@ -918,12 +912,6 @@ $('a[data-toggle="tab"]').on('shown', function (e) {

{{_i}}Object structure is: delay: { show: 500, hide: 100 }{{/i}}

- - {{_i}}ns{{/i}} - {{_i}}string{{/i}} - '.popover' - {{_i}}jQuery event namespace{{/i}} -
diff --git a/js/bootstrap-popover.js b/js/bootstrap-popover.js index 2a2b298dca..2e6d9c32a5 100644 --- a/js/bootstrap-popover.js +++ b/js/bootstrap-popover.js @@ -72,7 +72,7 @@ } , destroy: function () { - this.hide().$element.off(this.options.ns).removeData('popover') + this.hide().$element.off('.' + this.type).removeData(this.type) } }) @@ -97,7 +97,6 @@ placement: 'right' , content: '' , template: '

' - , ns: '.popover' }) }(window.jQuery); \ No newline at end of file diff --git a/js/bootstrap-tooltip.js b/js/bootstrap-tooltip.js index fa1c9a6c53..f9447410ec 100644 --- a/js/bootstrap-tooltip.js +++ b/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.ns, this.options.selector, $.proxy(this.enter, this)) - this.$element.on(eventOut + this.options.ns, 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 ? @@ -238,7 +238,7 @@ } , destroy: function () { - this.hide().$element.off(this.options.ns).removeData('tooltip') + this.hide().$element.off('.' + this.type).removeData(this.type) } } @@ -268,7 +268,6 @@ , title: '' , delay: 0 , html: true - , ns: '.tooltip' } }(window.jQuery);