diff options
author | John Resig <jeresig@gmail.com> | 2009-12-09 13:16:18 -0800 |
---|---|---|
committer | John Resig <jeresig@gmail.com> | 2009-12-09 13:16:18 -0800 |
commit | f6a0bf6816f4e2e67382b1b13fdd3ff2ea4b22f8 (patch) | |
tree | f3f8162c526aa7a8856425ae9f821cac8fe206f0 /src/data.js | |
parent | 4e27f17007c2329e31b449e61bb31197b90a37f1 (diff) | |
download | jquery-f6a0bf6816f4e2e67382b1b13fdd3ff2ea4b22f8.tar.gz jquery-f6a0bf6816f4e2e67382b1b13fdd3ff2ea4b22f8.zip |
Added support for .data(Object), overwriting the existing data object. Fixes #4284.
Diffstat (limited to 'src/data.js')
-rw-r--r-- | src/data.js | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/data.js b/src/data.js index 44aff0fd3..69adc1239 100644 --- a/src/data.js +++ b/src/data.js @@ -37,21 +37,24 @@ jQuery.extend({ // Avoid generating a new cache unless none exists and we // want to manipulate it. - if ( cache[ id ] ) { + if ( typeof name === "object" ) { + elem[ expando ] = id; + thisCache = cache[ id ] = jQuery.extend(true, {}, name); + } else if ( cache[ id ] ) { thisCache = cache[ id ]; } else if ( typeof data === "undefined" ) { thisCache = emptyObject; } else { thisCache = cache[ id ] = {}; } - + // Prevent overriding the named cache with undefined values if ( data !== undefined ) { elem[ expando ] = id; thisCache[ name ] = data; } - - return name ? thisCache[ name ] : thisCache; + + return typeof name === "string" ? thisCache[ name ] : thisCache; }, removeData: function( elem, name ) { @@ -100,6 +103,11 @@ jQuery.fn.extend({ data: function( key, value ){ if ( typeof key === "undefined" && this.length ) { return jQuery.data( this[0] ); + + } else if ( typeof key === "object" ) { + return this.each(function() { + jQuery.data( this, key ); + }); } var parts = key.split("."); |