From: Marc-Andre Lafortune Date: Sun, 7 Oct 2012 06:35:01 +0000 (-0400) Subject: Widget: Destroy only when element is the actual target. Fixes #8652 - Widget: Destroy... X-Git-Tag: 1.9.1~17 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8bb05d23e2c49ecbe2f83a3552efb0a93c48bb85;p=jquery-ui.git Widget: Destroy only when element is the actual target. Fixes #8652 - Widget: Destroy only when element is the actual target. --- 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 :