2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
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) {
99 val = valFn.call(this);
103 if (!cfg.readOnly && initValues) {
106 simple = initValues.simple;
107 if (simple && simple.hasOwnProperty(attr)) {
111 // Complex Attributes (complex values applied, after simple, incase both are set)
112 complex = initValues.complex;
113 if (complex && complex.hasOwnProperty(attr)) {
114 subvals = complex[attr];
115 for (i = 0, l = subvals.length; i < l; ++i) {
116 path = subvals[i].path;
117 subval = subvals[i].value;
118 O.setValue(val, path, subval);
127 Y.mix(Y.Attribute, Y.Attribute.Complex, true, null, 1);
130 }, '3.3.0' ,{requires:['attribute-base']});