aboutsummaryrefslogtreecommitdiffstats
path: root/src/data.js
diff options
context:
space:
mode:
authorJohn Resig <jeresig@gmail.com>2009-12-09 13:16:18 -0800
committerJohn Resig <jeresig@gmail.com>2009-12-09 13:16:18 -0800
commitf6a0bf6816f4e2e67382b1b13fdd3ff2ea4b22f8 (patch)
treef3f8162c526aa7a8856425ae9f821cac8fe206f0 /src/data.js
parent4e27f17007c2329e31b449e61bb31197b90a37f1 (diff)
downloadjquery-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.js16
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(".");