Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Merge pull request #455 from rwldrn/9413
Supports interoperable removal of hyphenated/camelCase properties. Fixes #9413
- Loading branch information
Showing
with
42 additions
and
2 deletions.
-
+14
−2
src/data.js
-
+28
−0
test/unit/data.js
|
@@ -135,7 +135,12 @@ jQuery.extend({ |
|
|
return; |
|
|
} |
|
|
|
|
|
var internalKey = jQuery.expando, isNode = elem.nodeType, |
|
|
var thisCache, |
|
|
|
|
|
// Reference to internal data cache key |
|
|
internalKey = jQuery.expando, |
|
|
|
|
|
isNode = elem.nodeType, |
|
|
|
|
|
// See jQuery.data for more information |
|
|
cache = isNode ? jQuery.cache : elem, |
|
@@ -150,9 +155,16 @@ jQuery.extend({ |
|
|
} |
|
|
|
|
|
if ( name ) { |
|
|
var thisCache = pvt ? cache[ id ][ internalKey ] : cache[ id ]; |
|
|
|
|
|
thisCache = pvt ? cache[ id ][ internalKey ] : cache[ id ]; |
|
|
|
|
|
if ( thisCache ) { |
|
|
|
|
|
// Support interoperable removal of hyphenated or camelcased keys |
|
|
if ( !thisCache[ name ] ) { |
|
|
name = jQuery.camelCase( name ); |
|
|
} |
|
|
|
|
|
delete thisCache[ name ]; |
|
|
|
|
|
// If there is no data left in the cache, we want to continue |
|
|
|
@@ -551,3 +551,31 @@ test("jQuery.data supports interoperable hyphenated/camelCase get/set of propert |
|
|
}); |
|
|
}); |
|
|
|
|
|
test("jQuery.data supports interoperable removal of hyphenated/camelCase properties", function() { |
|
|
var div = jQuery("<div/>", { id: "hyphened" }).appendTo("#qunit-fixture"), |
|
|
datas = { |
|
|
"non-empty": "a string", |
|
|
"empty-string": "", |
|
|
"one-value": 1, |
|
|
"zero-value": 0, |
|
|
"an-array": [], |
|
|
"an-object": {}, |
|
|
"bool-true": true, |
|
|
"bool-false": false, |
|
|
"some-json": '{ "foo": "bar" }' |
|
|
}; |
|
|
|
|
|
expect( 27 ); |
|
|
|
|
|
jQuery.each( datas, function( key, val ) { |
|
|
div.data( key, val ); |
|
|
|
|
|
deepEqual( div.data( key ), val, "get: " + key ); |
|
|
deepEqual( div.data( jQuery.camelCase( key ) ), val, "get: " + jQuery.camelCase( key ) ); |
|
|
|
|
|
div.removeData( key ); |
|
|
|
|
|
equal( div.data( key ), undefined, "get: " + key ); |
|
|
|
|
|
}); |
|
|
});
|