Skip to content

Commit

Permalink
Add Element.Layout#toObject and Element.Layout.toHash.
Browse files Browse the repository at this point in the history
  • Loading branch information
savetheclocktower committed Apr 18, 2010
1 parent 2fd5c9b commit 949dc83
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,3 +1,5 @@
Add `Element.Layout#toObject` and `Element.Layout.toHash`. (Andrew Dupont)

Make `Element.Layout#toCSS` return camelized property names, as expected by `Element.setStyle`. [#1021 state:resolved] (njakobsen, Andrew Dupont)

*1.7_rc1* (April 1, 2010)
Expand Down
39 changes: 39 additions & 0 deletions src/dom/layout.js
Expand Up @@ -338,6 +338,45 @@
return this._set(property, COMPUTATIONS[property].call(this, this.element));
},

/**
* Element.Layout#toObject([keys...]) -> Object
* - keys (String): A space-separated list of keys to include.
*
* Converts the layout hash to a plain object of key/value pairs,
* optionally including only the given keys.
*
* Keys can be passed into this method as individual arguments _or_
* separated by spaces within a string.
**/
toObject: function() {
var args = $A(arguments);
var keys = (args.length === 0) ? Element.Layout.PROPERTIES :
args.join(' ').split(' ');
var obj = {};
keys.each( function(key) {
// Key needs to be a valid Element.Layout property.
if (!Element.Layout.PROPERTIES.include(key)) return;
var value = this.get(key);
if (value != null) obj[key] = value;
});
return obj;
},

/**
* Element.Layout#toHash([keys...]) -> Hash
* - keys (String): A space-separated list of keys to include.
*
* Converts the layout hash to an ordinary hash of key/value pairs,
* optionally including only the given keys.
*
* Keys can be passed into this method as individual arguments _or_
* separated by spaces within a string.
**/
toHash: function() {
var obj = this.toObject.apply(this, arguments);
return new Hash(obj);
},

/**
* Element.Layout#toCSS([keys...]) -> Object
* - keys (String): A space-separated list of keys to include.
Expand Down

0 comments on commit 949dc83

Please sign in to comment.