Allow Element#store to accept an object containing several key/value pairs.
This commit is contained in:
parent
1ca385b18c
commit
c4f6066d2c
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
},
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue