i = 0;
for ( ; (elem = elems[ i ]) !== undefined; i++ ) {
- if ( jQuery.acceptData( elem ) && (data = elem[ dataPriv.expando ])) {
- if ( data.events ) {
- for ( type in data.events ) {
- if ( special[ type ] ) {
- jQuery.event.remove( elem, type );
-
- // This is a shortcut to avoid jQuery.event.remove's overhead
- } else {
- jQuery.removeEvent( elem, type, data.handle );
+ if ( jQuery.acceptData( elem ) ) {
+ if ( (data = elem[ dataPriv.expando ] ) ) {
+ if ( data.events ) {
+ for ( type in data.events ) {
+ if ( special[ type ] ) {
+ jQuery.event.remove( elem, type );
+
+ // This is a shortcut to avoid jQuery.event.remove's overhead
+ } else {
+ jQuery.removeEvent( elem, type, data.handle );
+ }
}
}
+ delete elem[ dataPriv.expando ];
+ }
+ if ( elem[ dataUser.expando ] ) {
+ delete elem[ dataUser.expando ];
}
- delete elem[ dataPriv.expando ];
}
}
}
});
test( "jQuery.cleanData eliminates all private data (gh-2127)", function() {
- expect( 2 );
+ expect( 3 );
var div = jQuery( "<div/>" ).appendTo( "#qunit-fixture" );
div.remove();
+ ok( !jQuery.hasData( div[ 0 ] ), "Removed element hasData should return false" );
+
ok( jQuery.isEmptyObject( jQuery._data( div[ 0 ] ) ),
"Private data is empty after node is removed" );
div.remove();
});
+test( "jQuery.cleanData eliminates all public data", function() {
+ expect( 2 );
+
+ var key,
+ div = jQuery( "<div/>" );
+ div.data( "some", "data" );
+ ok( !jQuery.isEmptyObject( jQuery.data( div[ 0 ] ) ), "Ensure some public data exists" );
+
+ div.remove();
+
+ ok( !jQuery.hasData( div[ 0 ] ), "Removed element hasData should return false" );
+
+ // Make sure the expando is gone
+ for ( key in div[ 0 ] ) {
+ if ( /^jQuery/.test( key ) ) {
+ ok( false, "Expando was not removed when there was no more data" );
+ }
+ }
+});
+
test( "domManip plain-text caching (trac-6779)", function() {
expect( 1 );