Skip to content
Permalink
Browse files

Landing pull request 512. 1.7 - removeData now takes space separated …

…lists and arrays of keys - Fixes #7323.

More Details:
 - #512
 - http://bugs.jquery.com/ticket/7323
  • Loading branch information...
gnarf authored and timmywil committed Sep 20, 2011
1 parent ca4133c commit 9b3768b968bc99d3422355e69e2c7c35bedf681e
Showing with 50 additions and 17 deletions.
  1. +17 −4 src/data.js
  2. +10 −12 src/event.js
  3. +23 −1 test/unit/data.js
@@ -133,7 +133,7 @@ jQuery.extend({
return;
}

var thisCache,
var thisCache, i, l,

// Reference to internal data cache key
internalKey = jQuery.expando,
@@ -158,12 +158,25 @@ jQuery.extend({

if ( thisCache ) {

// Support interoperable removal of hyphenated or camelcased keys
if ( !thisCache[ name ] ) {
// Support space separated names
if ( jQuery.isArray( name ) ) {
name = name;

This comment has been minimized.

Copy link
@pomeh

pomeh Nov 4, 2011

I'm not that good at Javascript but I'm wondering if this is really useful ?

This comment has been minimized.

Copy link
@rwaldron

rwaldron Nov 4, 2011

Member

It was useful enough to be requested in the 1.7 feature requests and voted in by the core and ui dev teams.

This comment has been minimized.

Copy link
@pomeh

pomeh Nov 4, 2011

Yeah yeah I've seen that, it's an awesome work BTW :)
But I was wondering what does the statement name = name; stands for ?

This comment has been minimized.

Copy link
@rwaldron

rwaldron Nov 4, 2011

Member

Oh, gotcha, the specific line. Sorry. @gnarf37 should weigh in?

This comment has been minimized.

Copy link
@timmywil

timmywil Nov 4, 2011

Member

Heh, yea that seems to be an oversight.

This comment has been minimized.

Copy link
@gnarf

gnarf Nov 5, 2011

Author Member

Wow.... blink nice catch ;) I'll fix it in a pull soon.

} else if ( name in thisCache ) {
name = [ name ];
} else {

// split the camel cased version by spaces
name = jQuery.camelCase( name );
if ( name in thisCache ) {
name = [ name ];
} else {
name = name.split( " " );
}
}

delete thisCache[ name ];
for ( i = 0, l = name.length; i < l; i++ ) {
delete thisCache[ name[i] ];
}

// If there is no data left in the cache, we want to continue
// and let the cache object itself get destroyed
@@ -238,20 +238,18 @@ jQuery.event = {

delete events[ type ];
}
}

// Remove the expando if it's no longer used
if ( jQuery.isEmptyObject( events ) ) {
handle = elemData.handle;
if ( handle ) {
handle.elem = null;
}

delete elemData.events;

// removeData also checks for emptiness and clears the expando if empty
// so use it instead of delete for this last property we touch here
jQuery.removeData( elem, "handle", true );
// Remove the expando if it's no longer used
if ( jQuery.isEmptyObject( events ) ) {
handle = elemData.handle;
if ( handle ) {
handle.elem = null;
}

// removeData also checks for emptiness and clears the expando if empty
// so use it instead of delete
jQuery.removeData( elem, [ "events", "handle" ], true );
}
},

@@ -434,7 +434,7 @@ test(".data(Object)", function() {
});

test("jQuery.removeData", function() {
expect(6);
expect(10);
var div = jQuery("#foo")[0];
jQuery.data(div, "test", "testing");
jQuery.removeData(div, "test");
@@ -445,6 +445,28 @@ test("jQuery.removeData", function() {
ok( !jQuery.data(div, "test2"), "Make sure that the data property no longer exists." );
ok( !div[ jQuery.expando ], "Make sure the expando no longer exists, as well." );

jQuery.data(div, {
test3: "testing",
test4: "testing"
});
jQuery.removeData( div, "test3 test4" );
ok( !jQuery.data(div, "test3") || jQuery.data(div, "test4"), "Multiple delete with spaces." );

jQuery.data(div, {
test3: "testing",
test4: "testing"
});
jQuery.removeData( div, [ "test3", "test4" ] );
ok( !jQuery.data(div, "test3") || jQuery.data(div, "test4"), "Multiple delete by array." );

jQuery.data(div, {
"test3 test4": "testing",
test3: "testing"
});
jQuery.removeData( div, "test3 test4" );
ok( !jQuery.data(div, "test3 test4"), "Multiple delete with spaces deleted key with exact name" );
ok( jQuery.data(div, "test3"), "Left the partial matched key alone" );

var obj = {};
jQuery.data(obj, "test", "testing");
equals( jQuery(obj).data("test"), "testing", "verify data on plain object");

0 comments on commit 9b3768b

Please sign in to comment.
You can’t perform that action at this time.