aboutsummaryrefslogtreecommitdiffstats
path: root/src/data.js
diff options
context:
space:
mode:
authorInfinitiesLoop <dareed@microsoft.com>2010-07-21 05:53:36 +0800
committerJohn Resig <jeresig@gmail.com>2010-07-23 03:52:01 +0800
commit9faab0b74fd316c2161612236d9ea8a01f3c78f8 (patch)
treece936d07187d1bb6e695d5fc21de241371fd8edb /src/data.js
parentef9fb80cabc8c8f9cbcf71bf9160de0abdaa2de8 (diff)
downloadjquery-9faab0b74fd316c2161612236d9ea8a01f3c78f8.tar.gz
jquery-9faab0b74fd316c2161612236d9ea8a01f3c78f8.zip
Ticket #6808. Changes data() so on plain objects, it uses a function to contain the cache ID to avoid it being JSON serialized.
Diffstat (limited to 'src/data.js')
-rw-r--r--src/data.js29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/data.js b/src/data.js
index f7af18d0d..6dcfb4c22 100644
--- a/src/data.js
+++ b/src/data.js
@@ -46,13 +46,30 @@ jQuery.extend({
// Avoid generating a new cache unless none exists and we
// want to manipulate it.
if ( typeof name === "object" ) {
- cache[ id ] = jQuery.extend(true, {}, name);
+ if ( isNode ) {
+ cache[ id ] = jQuery.extend(true, {}, name);
+ } else {
+ cache[ id ] = function() {
+ return jQuery.extend(true, {}, name);
+ }
+ }
} else if ( !cache[ id ] ) {
- cache[ id ] = {};
+ if ( isNode ) {
+ cache[ id ] = {};
+ } else {
+ var store = {};
+ cache[ id ] = function() {
+ return store;
+ }
+ }
+
}
thisCache = cache[ id ];
+ if ( !isNode ) {
+ thisCache = thisCache();
+ }
// Prevent overriding the named cache with undefined values
if ( data !== undefined ) {
@@ -71,8 +88,12 @@ jQuery.extend({
windowData :
elem;
- var id = elem[ jQuery.expando ], cache = jQuery.cache,
- isNode = elem.nodeType, thisCache = isNode ? cache[ id ] : id;
+ var isNode = elem.nodeType,
+ id = elem[ jQuery.expando ], cache = jQuery.cache;
+ if ( id && !isNode ) {
+ id = id();
+ }
+ var thisCache = cache[ id ];
// If we want to remove a specific section of the element's data
if ( name ) {