Widget: Destroy only when element is the actual target. Fixes #8652 - Widget: Destroy only when element is the actual target.

This commit is contained in:
Marc-Andre Lafortune 2012-10-07 02:35:01 -04:00 committed by Scott González
parent b1b07e8046
commit 8bb05d23e2
2 changed files with 14 additions and 1 deletions

View 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() {

View 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 :