~ubuntu-branches/ubuntu/precise/whoopsie-daisy/precise-proposed

« back to all changes in this revision

Viewing changes to backend/stats/static/js/yui/3.4.1/build/attribute-complex/attribute-complex.js

  • Committer: Package Import Robot
  • Author(s): Evan Dandrea
  • Date: 2012-04-18 13:04:36 UTC
  • Revision ID: package-import@ubuntu.com-20120418130436-vmt93p8fds516lws
Tags: 0.1.32
Fix failing tests on powerpc and ARM.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
YUI 3.4.1 (build 4118)
3
 
Copyright 2011 Yahoo! Inc. All rights reserved.
4
 
Licensed under the BSD License.
5
 
http://yuilibrary.com/license/
6
 
*/
7
 
YUI.add('attribute-complex', function(Y) {
8
 
 
9
 
    /**
10
 
     * Adds support for attribute providers to handle complex attributes in the constructor
11
 
     *
12
 
     * @module attribute
13
 
     * @submodule attribute-complex
14
 
     * @for Attribute
15
 
     */
16
 
 
17
 
    var O = Y.Object,
18
 
        DOT = ".";
19
 
 
20
 
    Y.Attribute.Complex = function() {};
21
 
    Y.Attribute.Complex.prototype = {
22
 
 
23
 
        /**
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.
27
 
         *
28
 
         * @method _normAttrVals
29
 
         * @param {Object} valueHash An object with attribute name/value pairs
30
 
         *
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.
34
 
         *
35
 
         * @private
36
 
         */
37
 
        _normAttrVals : function(valueHash) {
38
 
            var vals = {},
39
 
                subvals = {},
40
 
                path,
41
 
                attr,
42
 
                v, k;
43
 
 
44
 
            if (valueHash) {
45
 
                for (k in valueHash) {
46
 
                    if (valueHash.hasOwnProperty(k)) {
47
 
                        if (k.indexOf(DOT) !== -1) {
48
 
                            path = k.split(DOT);
49
 
                            attr = path.shift();
50
 
                            v = subvals[attr] = subvals[attr] || [];
51
 
                            v[v.length] = {
52
 
                                path : path, 
53
 
                                value: valueHash[k]
54
 
                            };
55
 
                        } else {
56
 
                            vals[k] = valueHash[k];
57
 
                        }
58
 
                    }
59
 
                }
60
 
                return { simple:vals, complex:subvals };
61
 
            } else {
62
 
                return null;
63
 
            }
64
 
        },
65
 
 
66
 
        /**
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.
71
 
         *
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
75
 
         *
76
 
         * @return {Any} The initial value of the attribute.
77
 
         *
78
 
         * @method _getAttrInitVal
79
 
         * @private
80
 
         */
81
 
        _getAttrInitVal : function(attr, cfg, initValues) {
82
 
 
83
 
            var val = cfg.value,
84
 
                valFn = cfg.valueFn,
85
 
                simple,
86
 
                complex,
87
 
                i,
88
 
                l,
89
 
                path,
90
 
                subval,
91
 
                subvals;
92
 
 
93
 
            if (valFn) {
94
 
                if (!valFn.call) {
95
 
                    valFn = this[valFn];
96
 
                }
97
 
                if (valFn) {
98
 
                    val = valFn.call(this);
99
 
                }
100
 
            }
101
 
 
102
 
            if (!cfg.readOnly && initValues) {
103
 
 
104
 
                // Simple Attributes
105
 
                simple = initValues.simple;
106
 
                if (simple && simple.hasOwnProperty(attr)) {
107
 
                    val = simple[attr];
108
 
                }
109
 
 
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);
118
 
                    }
119
 
                }
120
 
            }
121
 
 
122
 
            return val;
123
 
        }
124
 
    };
125
 
 
126
 
    Y.mix(Y.Attribute, Y.Attribute.Complex, true, null, 1);
127
 
 
128
 
 
129
 
}, '3.4.1' ,{requires:['attribute-base']});