]> source.dussan.org Git - jquery-ui.git/commitdiff
Widget: Destroy only when element is the actual target. Fixes #8652 - Widget: Destroy...
authorMarc-Andre Lafortune <github@marc-andre.ca>
Sun, 7 Oct 2012 06:35:01 +0000 (02:35 -0400)
committerScott González <scott.gonzalez@gmail.com>
Tue, 23 Oct 2012 18:06:30 +0000 (14:06 -0400)
tests/unit/widget/widget_core.js
ui/jquery.ui.widget.js

index 848579a1dcc2496d284c02d1f32bb6d64615b7bc..31f2b9ccffcb0f0d08fcb1ccbe6aa2c6806e9727 100644 (file)
@@ -1167,6 +1167,13 @@ test( "._trigger() - instance as element", function() {
                        $( "#widget" ).testWidget().detach();
                });
        });
+
+       test( "destroy - remove event bubbling", function() {
+               shouldDestroy( false, function() {
+                       $( "<div>child</div>" ).appendTo( $( "#widget" ).testWidget() )
+                               .trigger( "remove" );
+               });
+       });
 }());
 
 test( "redefine", function() {
index 05487f7edb87fc7d96d56a855e74ac8c1079e56c..ccbe0cac58f6b10e37fdacc157f815bf1513b610 100644 (file)
@@ -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 :