2 Copyright (c) 2009, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.net/yui/license.txt
8 YUI.add('attribute-complex', function(Y) {
11 * Adds support for attribute providers to handle complex attributes in the constructor
14 * @submodule attribute-complex
21 Y.Attribute.Complex = function() {};
22 Y.Attribute.Complex.prototype = {
25 * Utility method to split out simple attribute name/value pairs ("x")
26 * from complex attribute name/value pairs ("x.y.z"), so that complex
27 * attributes can be keyed by the top level attribute name.
29 * @method _normAttrVals
30 * @param {Object} valueHash An object with attribute name/value pairs
32 * @return {Object} An object literal with 2 properties - "simple" and "complex",
33 * containing simple and complex attribute values respectively keyed
34 * by the top level attribute name, or null, if valueHash is falsey.
38 _normAttrVals : function(valueHash) {
46 for (k in valueHash) {
47 if (valueHash.hasOwnProperty(k)) {
48 if (k.indexOf(DOT) !== -1) {
51 v = subvals[attr] = subvals[attr] || [];
57 vals[k] = valueHash[k];
61 return { simple:vals, complex:subvals };
68 * Returns the initial value of the given attribute from
69 * either the default configuration provided, or the
70 * over-ridden value if it exists in the set of initValues
71 * provided and the attribute is not read-only.
73 * @param {String} attr The name of the attribute
74 * @param {Object} cfg The attribute configuration object
75 * @param {Object} initValues The object with simple and complex attribute name/value pairs returned from _normAttrVals
77 * @return {Any} The initial value of the attribute.
79 * @method _getAttrInitVal
82 _getAttrInitVal : function(attr, cfg, initValues) {
84 var val = (cfg.valueFn) ? cfg.valueFn.call(this) : cfg.value,
93 if (!cfg.readOnly && initValues) {
96 simple = initValues.simple;
97 if (simple && simple.hasOwnProperty(attr)) {
101 // Complex Attributes (complex values applied, after simple, incase both are set)
102 complex = initValues.complex;
103 if (complex && complex.hasOwnProperty(attr)) {
104 subvals = complex[attr];
105 for (i = 0, l = subvals.length; i < l; ++i) {
106 path = subvals[i].path;
107 subval = subvals[i].value;
108 O.setValue(val, path, subval);
117 Y.mix(Y.Attribute, Y.Attribute.Complex, true, null, 1);
120 }, '3.0.0' ,{requires:['attribute-base']});