3
Copyright 2011 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
7
YUI.add('attribute-complex', function(Y) {
10
* Adds support for attribute providers to handle complex attributes in the constructor
13
* @submodule attribute-complex
20
Y.Attribute.Complex = function() {};
21
Y.Attribute.Complex.prototype = {
24
* Utility method to split out simple attribute name/value pairs ("x")
25
* from complex attribute name/value pairs ("x.y.z"), so that complex
26
* attributes can be keyed by the top level attribute name.
28
* @method _normAttrVals
29
* @param {Object} valueHash An object with attribute name/value pairs
31
* @return {Object} An object literal with 2 properties - "simple" and "complex",
32
* containing simple and complex attribute values respectively keyed
33
* by the top level attribute name, or null, if valueHash is falsey.
37
_normAttrVals : function(valueHash) {
45
for (k in valueHash) {
46
if (valueHash.hasOwnProperty(k)) {
47
if (k.indexOf(DOT) !== -1) {
50
v = subvals[attr] = subvals[attr] || [];
56
vals[k] = valueHash[k];
60
return { simple:vals, complex:subvals };
67
* Returns the initial value of the given attribute from
68
* either the default configuration provided, or the
69
* over-ridden value if it exists in the set of initValues
70
* provided and the attribute is not read-only.
72
* @param {String} attr The name of the attribute
73
* @param {Object} cfg The attribute configuration object
74
* @param {Object} initValues The object with simple and complex attribute name/value pairs returned from _normAttrVals
76
* @return {Any} The initial value of the attribute.
78
* @method _getAttrInitVal
81
_getAttrInitVal : function(attr, cfg, initValues) {
98
val = valFn.call(this);
102
if (!cfg.readOnly && initValues) {
105
simple = initValues.simple;
106
if (simple && simple.hasOwnProperty(attr)) {
110
// Complex Attributes (complex values applied, after simple, incase both are set)
111
complex = initValues.complex;
112
if (complex && complex.hasOwnProperty(attr)) {
113
subvals = complex[attr];
114
for (i = 0, l = subvals.length; i < l; ++i) {
115
path = subvals[i].path;
116
subval = subvals[i].value;
117
O.setValue(val, path, subval);
126
Y.mix(Y.Attribute, Y.Attribute.Complex, true, null, 1);
129
}, '3.4.1' ,{requires:['attribute-base']});