core: Fixed #2605: .data() now accepts null as a value.

This commit is contained in:
Scott González 2008-05-03 01:51:55 +00:00
parent ad3c49d1b6
commit f8698395ac
2 changed files with 11 additions and 6 deletions

View file

@ -465,13 +465,13 @@ jQuery.fn = jQuery.prototype = {
var parts = key.split(".");
parts[1] = parts[1] ? "." + parts[1] : "";
if ( value == null ) {
if ( value === undefined ) {
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 );
return data == null && parts[1] ?
return data === undefined && parts[1] ?
this.data( parts[0] ) :
data;
} else

View file

@ -1412,14 +1412,19 @@ test("$.data", function() {
});
test(".data()", function() {
expect(16);
expect(18);
var div = $("#foo");
ok( div.data("test") == undefined, "Check for no data exists" );
div.data("test", "success");
ok( div.data("test") == "success", "Check for added data" );
div.data("test", "overwritten");
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};
div