Implemented .data() to get the entire data object. Closes #4284
authorYehuda Katz <wycats@gmail.com>
Thu, 16 Jul 2009 07:32:25 +0000 (07:32 +0000)
committerYehuda Katz <wycats@gmail.com>
Thu, 16 Jul 2009 07:32:25 +0000 (07:32 +0000)
src/data.js
test/unit/data.js

index bf54e75..1d5fe89 100644 (file)
@@ -23,6 +23,8 @@ jQuery.extend({
                if ( data !== undefined )\r
                        jQuery.cache[ id ][ name ] = data;\r
 \r
+               if(name === true) return jQuery.cache[ id ]\r
+\r
                // Return the named cache data, or the ID for the element\r
                return name ?\r
                        jQuery.cache[ id ][ name ] :\r
@@ -98,6 +100,8 @@ jQuery.extend({
 \r
 jQuery.fn.extend({\r
        data: function( key, value ){\r
+               if(typeof key === "undefined" && this.length) return jQuery.data(this[0], true);\r
+\r
                var parts = key.split(".");\r
                parts[1] = parts[1] ? "." + parts[1] : "";\r
 \r
index 812ccd2..14483a1 100644 (file)
@@ -15,6 +15,14 @@ test("jQuery.data", function() {
 });\r
 \r
 test(".data()", function() {\r
+       expect(1);\r
+\r
+       var div = jQuery("#foo");\r
+       div.data("test", "success");\r
+       isObj( div.data(), {test: "success"}, "data() get the entire data object" )\r
+})\r
+\r
+test(".data(String) and .data(String, Object)", function() {\r
        expect(22);\r
        var div = jQuery("#foo");\r
        equals( div.data("test"), undefined, "Check for no data exists" );\r