diff --git a/CHANGELOG b/CHANGELOG index fef6704..d0eaf3d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Allow Element#store to accept an object containing several key/value pairs. (ZenCocoon, Andrew Dupont) + * 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) diff --git a/src/dom/dom.js b/src/dom/dom.js index 1f331d6..18e0ffc 100644 --- a/src/dom/dom.js +++ b/src/dom/dom.js @@ -1231,7 +1231,14 @@ Element.addMethods({ store: function(element, key, value) { if (!(element = $(element))) return; - element.getStorage().set(key, value); + + if (Object.isString(key)) { + element.getStorage().set(key, value); + } else { + // Assume we've been passed an object full of key/value pairs. + element.getStorage().update(key); + } + return element; }, diff --git a/test/unit/dom_test.js b/test/unit/dom_test.js index 00f6f19..4e02c5f 100644 --- a/test/unit/dom_test.js +++ b/test/unit/dom_test.js @@ -1380,6 +1380,11 @@ new Test.Unit.Runner({ element.getStorage().unset('bar'); this.assertEnumEqual($w('foo'), element.getStorage().keys(), "Getting the storage hash after unsetting a key"); + element.store({ 'narf': 'narf', 'zort': 'zort' }); + + this.assertEqual("narf", element.retrieve('narf'), "Storing multiple properties at once"); + this.assertEqual("zort", element.retrieve('zort'), "Storing multiple properties at once"); + 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 has been set properly");