Widget: Hook into jQuery.cleanData to auto-destroy widgets. Fixes #60…
…08 - Widget: auto-destroy is broken in jQuery 1.4.
- Loading branch information
- +3 −1 tests/unit/widget/widget.html
- +67 −0 tests/unit/widget/widget_core.js
- +23 −13 ui/jquery.ui.widget.js
| @@ -9,20 +9,30 @@ | ||
| */ | ||
| (function( $, undefined ) { | ||
|
|
||
| var _remove = $.fn.remove; | ||
|
|
||
| $.fn.remove = function( selector, keepData ) { | ||
| return this.each(function() { | ||
| if ( !keepData ) { | ||
| if ( !selector || $.filter( selector, [ this ] ).length ) { | ||
| $( "*", this ).add( [ this ] ).each(function() { | ||
| $( this ).triggerHandler( "remove" ); | ||
| }); | ||
| } | ||
| // jQuery 1.4+ | ||
| if ( $.cleanData ) { | ||
| var _cleanData = $.cleanData; | ||
| $.cleanData = function( elems ) { | ||
| for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) { | ||
| $( elem ).triggerHandler( "remove" ); | ||
| } | ||
| return _remove.call( $(this), selector, keepData ); | ||
| }); | ||
| }; | ||
| _cleanData( elems ); | ||
This comment has been minimized.
This comment has been minimized.
scottgonzalez
Author
Member
|
||
| }; | ||
| } else { | ||
| var _remove = $.fn.remove; | ||
| $.fn.remove = function( selector, keepData ) { | ||
| return this.each(function() { | ||
| if ( !keepData ) { | ||
| if ( !selector || $.filter( selector, [ this ] ).length ) { | ||
| $( "*", this ).add( [ this ] ).each(function() { | ||
| $( this ).triggerHandler( "remove" ); | ||
| }); | ||
| } | ||
| } | ||
| return _remove.call( $(this), selector, keepData ); | ||
| }); | ||
| }; | ||
| } | ||
|
|
||
| $.widget = function( name, base, prototype ) { | ||
| var namespace = name.split( "." )[ 0 ], | ||
2 comments
on commit 0a0a39f
This comment has been minimized.
This comment has been minimized.
|
Why destroy widgets on detach? |
This comment has been minimized.
This comment has been minimized.
|
We don't, the test makes sure that destroy isn't called on .detach(). |
There's an additional (internal) argument 'acceptData' in jQuery.cleanData - why's that not passed here?
(seems to be a perf.opt. as it just prevents some duplicate calls to jQuery.acceptData)