core: Fixed #2605: .data() now accepts null as a value.
This commit is contained in:
parent
ad3c49d1b6
commit
f8698395ac
|
@ -465,13 +465,13 @@ jQuery.fn = jQuery.prototype = {
|
||||||
var parts = key.split(".");
|
var parts = key.split(".");
|
||||||
parts[1] = parts[1] ? "." + parts[1] : "";
|
parts[1] = parts[1] ? "." + parts[1] : "";
|
||||||
|
|
||||||
if ( value == null ) {
|
if ( value === undefined ) {
|
||||||
var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);
|
var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);
|
||||||
|
|
||||||
if ( data == undefined && this.length )
|
if ( data === undefined && this.length )
|
||||||
data = jQuery.data( this[0], key );
|
data = jQuery.data( this[0], key );
|
||||||
|
|
||||||
return data == null && parts[1] ?
|
return data === undefined && parts[1] ?
|
||||||
this.data( parts[0] ) :
|
this.data( parts[0] ) :
|
||||||
data;
|
data;
|
||||||
} else
|
} else
|
||||||
|
|
|
@ -1412,14 +1412,19 @@ test("$.data", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test(".data()", function() {
|
test(".data()", function() {
|
||||||
expect(16);
|
expect(18);
|
||||||
var div = $("#foo");
|
var div = $("#foo");
|
||||||
ok( div.data("test") == undefined, "Check for no data exists" );
|
ok( div.data("test") == undefined, "Check for no data exists" );
|
||||||
div.data("test", "success");
|
div.data("test", "success");
|
||||||
ok( div.data("test") == "success", "Check for added data" );
|
ok( div.data("test") == "success", "Check for added data" );
|
||||||
div.data("test", "overwritten");
|
div.data("test", "overwritten");
|
||||||
ok( div.data("test") == "overwritten", "Check for overwritten data" );
|
ok( div.data("test") == "overwritten", "Check for overwritten data" );
|
||||||
|
div.data("test", undefined);
|
||||||
|
ok( div.data("test") == "overwritten", "Check that data wasn't removed");
|
||||||
|
div.data("test", null);
|
||||||
|
ok( div.data("test") === null, "Check for null data");
|
||||||
|
|
||||||
|
div.data("test", "overwritten");
|
||||||
var hits = {test:0}, gets = {test:0};
|
var hits = {test:0}, gets = {test:0};
|
||||||
|
|
||||||
div
|
div
|
||||||
|
|
Loading…
Reference in a new issue