From 1ca385b18c79ab510c6955c07f9f2bc53cfdd2ae Mon Sep 17 00:00:00 2001 From: savetheclocktower Date: Mon, 15 Dec 2008 09:41:10 -0600 Subject: [PATCH] Change Element#retrieve to return the element itself (for chaining). --- CHANGELOG | 2 ++ src/dom/dom.js | 1 + test/unit/dom_test.js | 5 +++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2626a17..fef6704 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Change Element#retrieve to return the element itself (for chaining). (Andrew Dupont) + * Add non-bubbling custom events. A new final argument to Element#fire defaults to `true`; pass `false` to prevent bubbling when firing a custom event. (Andrew Dupont) * Alter event system to use new element storage API rather than have its own global hashtable. (Andrew Dupont) diff --git a/src/dom/dom.js b/src/dom/dom.js index 4cfbe20..1f331d6 100644 --- a/src/dom/dom.js +++ b/src/dom/dom.js @@ -1232,6 +1232,7 @@ Element.addMethods({ store: function(element, key, value) { if (!(element = $(element))) return; element.getStorage().set(key, value); + return element; }, retrieve: function(element, key, defaultValue) { diff --git a/test/unit/dom_test.js b/test/unit/dom_test.js index f82e01e..00f6f19 100644 --- a/test/unit/dom_test.js +++ b/test/unit/dom_test.js @@ -1371,8 +1371,9 @@ new Test.Unit.Runner({ var element = $('test-empty'); element.store('foo', 'bar'); this.assertEqual("bar", element.retrieve("foo"), "Setting and reading a property"); - element.store('foo', 'thud'); + var result = element.store('foo', 'thud'); this.assertEqual("thud", element.retrieve("foo"), "Re-setting and reading property"); + this.assertIdentical(element, result, "Element#store should return element"); element.store('bar', 'narf'); this.assertEnumEqual($w('foo bar'), element.getStorage().keys(), "Getting the storage hash"); @@ -1381,7 +1382,7 @@ new Test.Unit.Runner({ this.assertUndefined(element.retrieve('bar'), "Undefined key should return undefined if default value is not defined"); this.assertEqual("default", element.retrieve('bar', 'default'), "Return default value if undefined key"); - this.assertEqual("default", element.retrieve('bar'), "Makes sure default value as been set properly"); + this.assertEqual("default", element.retrieve('bar'), "Makes sure default value has been set properly"); var clonedElement = $('test-empty').cloneNode(false); this.assert(!('_prototypeUID' in clonedElement), "Cloning a node should not confuse the storage engine");