Make .data(Object) extend the existing data object. Fixes #6692.
This commit is contained in:
parent
626624a19a
commit
0b4b3ee8a5
2 changed files with 8 additions and 4 deletions
|
@ -52,9 +52,10 @@ jQuery.extend({
|
||||||
// want to manipulate it.
|
// want to manipulate it.
|
||||||
if ( typeof name === "object" ) {
|
if ( typeof name === "object" ) {
|
||||||
if ( isNode ) {
|
if ( isNode ) {
|
||||||
cache[ id ] = jQuery.extend(true, {}, name);
|
cache[ id ] = jQuery.extend(cache[ id ], name);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
store = jQuery.extend(true, {}, name);
|
store = jQuery.extend(cache[ id ], name);
|
||||||
cache[ id ] = function() {
|
cache[ id ] = function() {
|
||||||
return store;
|
return store;
|
||||||
};
|
};
|
||||||
|
@ -63,6 +64,7 @@ jQuery.extend({
|
||||||
} else if ( !cache[ id ] ) {
|
} else if ( !cache[ id ] ) {
|
||||||
if ( isNode ) {
|
if ( isNode ) {
|
||||||
cache[ id ] = {};
|
cache[ id ] = {};
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
store = {};
|
store = {};
|
||||||
cache[ id ] = function() {
|
cache[ id ] = function() {
|
||||||
|
|
|
@ -25,7 +25,7 @@ test("expando", function(){
|
||||||
});
|
});
|
||||||
|
|
||||||
test("jQuery.data", function() {
|
test("jQuery.data", function() {
|
||||||
expect(12);
|
expect(13);
|
||||||
var div = document.createElement("div");
|
var div = document.createElement("div");
|
||||||
|
|
||||||
ok( jQuery.data(div, "test") === undefined, "Check for no data exists" );
|
ok( jQuery.data(div, "test") === undefined, "Check for no data exists" );
|
||||||
|
@ -47,9 +47,11 @@ test("jQuery.data", function() {
|
||||||
jQuery.data(div, "test", null);
|
jQuery.data(div, "test", null);
|
||||||
ok( jQuery.data(div, "test") === null, "Check for null data");
|
ok( jQuery.data(div, "test") === null, "Check for null data");
|
||||||
|
|
||||||
|
jQuery.data(div, "test3", "orig");
|
||||||
jQuery.data(div, { "test": "in", "test2": "in2" });
|
jQuery.data(div, { "test": "in", "test2": "in2" });
|
||||||
equals( jQuery.data(div, "test"), "in", "Verify setting an object in data." );
|
equals( jQuery.data(div, "test"), "in", "Verify setting an object in data." );
|
||||||
equals( jQuery.data(div, "test2"), "in2", "Verify setting an object in data." );
|
equals( jQuery.data(div, "test2"), "in2", "Verify setting an object in data." );
|
||||||
|
equals( jQuery.data(div, "test3"), "orig", "Verify original not overwritten." );
|
||||||
|
|
||||||
var obj = {};
|
var obj = {};
|
||||||
jQuery.data( obj, "prop", true );
|
jQuery.data( obj, "prop", true );
|
||||||
|
@ -61,7 +63,7 @@ test("jQuery.data", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test(".data()", function() {
|
test(".data()", function() {
|
||||||
expect(1);
|
expect(2);
|
||||||
|
|
||||||
var div = jQuery("#foo");
|
var div = jQuery("#foo");
|
||||||
div.data("test", "success");
|
div.data("test", "success");
|
||||||
|
|
Loading…
Add table
Reference in a new issue