Change Element#retrieve to return the element itself (for chaining).

This commit is contained in:
savetheclocktower 2008-12-15 09:41:10 -06:00
parent f8a25223d0
commit 1ca385b18c
3 changed files with 6 additions and 2 deletions

View File

@ -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)

View File

@ -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) {

View File

@ -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");