10000 Widget: Destroy only when element is the actual target. Fixes #8652 -… · faroncoder/jquery-ui@8bb05d2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8bb05d2

Browse files
marcandrescottgonzalez
authored andcommitted
Widget: Destroy only when element is the actual target. Fixes #8652 - Widget: Destroy only when element is the actual target.
1 parent b1b07e8 commit 8bb05d2

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

tests/unit/widget/widget_core.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,13 @@ test( "._trigger() - instance as element", function() {
11671167
$( "#widget" ).testWidget().detach();
11681168
});
11691169
});
1170+
1171+
test( "destroy - remove event bubbling", function() {
1172+
shouldDestroy( false, function() {
1173+
$( "<div>child</div>" ).appendTo( $( "#widget" ).testWidget() )
1174+
.trigger( "remove" );
1175+
});
1176+
});
11701177
}());
11711178

11721179
test( "redefine", function() {

ui/jquery.ui.widget.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,13 @@ $.Widget.prototype = {
237237
// TODO remove dual storage
238238
$.data( element, this.widgetName, this );
239239
$.data( element, this.widgetFullName, this );
240-
this._on({ remove: "destroy" });
240+
this._on({
241+
remove: function( event ) {
242+
if ( event.target === element ) {
243+
this.destroy();
244+
}
245+
}
246+
});
241247
this.document = $( element.style ?
242248
// element within the document
243249
element.ownerDocument :

0 commit comments

Comments
 (0)
0