From: Yehuda Katz Date: Thu, 16 Jul 2009 07:32:25 +0000 (+0000) Subject: Implemented .data() to get the entire data object. Closes #4284 X-Git-Url: http://git.asbjorn.biz/?p=jquery.git;a=commitdiff_plain;h=d36d224cc52e70d837306d33a03f517ef72abc60 Implemented .data() to get the entire data object. Closes #4284 --- diff --git a/src/data.js b/src/data.js index bf54e75..1d5fe89 100644 --- a/src/data.js +++ b/src/data.js @@ -23,6 +23,8 @@ jQuery.extend({ if ( data !== undefined ) jQuery.cache[ id ][ name ] = data; + if(name === true) return jQuery.cache[ id ] + // Return the named cache data, or the ID for the element return name ? jQuery.cache[ id ][ name ] : @@ -98,6 +100,8 @@ jQuery.extend({ jQuery.fn.extend({ data: function( key, value ){ + if(typeof key === "undefined" && this.length) return jQuery.data(this[0], true); + var parts = key.split("."); parts[1] = parts[1] ? "." + parts[1] : ""; diff --git a/test/unit/data.js b/test/unit/data.js index 812ccd2..14483a1 100644 --- a/test/unit/data.js +++ b/test/unit/data.js @@ -15,6 +15,14 @@ test("jQuery.data", function() { }); test(".data()", function() { + expect(1); + + var div = jQuery("#foo"); + div.data("test", "success"); + isObj( div.data(), {test: "success"}, "data() get the entire data object" ) +}) + +test(".data(String) and .data(String, Object)", function() { expect(22); var div = jQuery("#foo"); equals( div.data("test"), undefined, "Check for no data exists" );