From 8bb05d23e2c49ecbe2f83a3552efb0a93c48bb85 Mon Sep 17 00:00:00 2001 From: Marc-Andre Lafortune Date: Sun, 7 Oct 2012 02:35:01 -0400 Subject: [PATCH] Widget: Destroy only when element is the actual target. Fixes #8652 - Widget: Destroy only when element is the actual target. --- tests/unit/widget/widget_core.js | 7 +++++++ ui/jquery.ui.widget.js | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/unit/widget/widget_core.js b/tests/unit/widget/widget_core.js index 848579a1d..31f2b9ccf 100644 --- a/tests/unit/widget/widget_core.js +++ b/tests/unit/widget/widget_core.js @@ -1167,6 +1167,13 @@ test( "._trigger() - instance as element", function() { $( "#widget" ).testWidget().detach(); }); }); + + test( "destroy - remove event bubbling", function() { + shouldDestroy( false, function() { + $( "
child
" ).appendTo( $( "#widget" ).testWidget() ) + .trigger( "remove" ); + }); + }); }()); test( "redefine", function() { diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js index 05487f7ed..ccbe0cac5 100644 --- a/ui/jquery.ui.widget.js +++ b/ui/jquery.ui.widget.js @@ -237,7 +237,13 @@ $.Widget.prototype = { // TODO remove dual storage $.data( element, this.widgetName, this ); $.data( element, this.widgetFullName, this ); - this._on({ remove: "destroy" }); + this._on({ + remove: function( event ) { + if ( event.target === element ) { + this.destroy(); + } + } + }); this.document = $( element.style ? // element within the document element.ownerDocument : -- 2.39.5