Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
YUI.add('anim-shape', function (Y, NAME) {
2
 
3
/**
4
 * Adds support for the <code>transform</code> attribute of <code>Graphic</code>
5
 * <code>Shape</code> instances.
6
 * @module anim
7
 * @submodule anim-shape-transform
8
 * @deprecated Use anim-shape instead.
9
 */
10
/**
11
 * Adds support for the <code>transform</code> and <code>fill</code> attributes of <code>Graphic</code>
12
 * and <code>Shape</code> instances. The <code>anim-shape</code> submodule can be used for all animations
13
 * involving <code>Graphic</code> <code>Shape</code> attributes.
14
 *
15
 * @module anim
16
 * @submodule anim-shape
17
 */
18
    var NUM = Number,
19
    TO,
20
    TOSTRING,
21
    COLOR = "color",
22
    STOPS = "stops",
23
    TYPE = "type",
24
    GETUPDATEDSTOPS = function(anim, from, to, elapsed, duration, fn)
25
    {
26
        var i = 0,
27
            getUpdatedColorValue = Y.Anim.getUpdatedColorValue,
28
            toStop,
29
            fromStop,
30
            prop,
31
            len = to.length,
32
            stops = [],
33
            stop;
34
        for(; i < len; i = i + 1)
35
        {
36
            toStop = to[i];
37
            fromStop = from[i];
38
            stop = {};
39
            for(prop in toStop)
40
            {
41
                if(toStop.hasOwnProperty(prop))
42
                {
43
                    if(prop === COLOR)
44
                    {
45
                        stop[prop] = Y.Color.toHex(getUpdatedColorValue(
46
                            Y.Color.toHex(fromStop[prop]),
47
                            Y.Color.toHex(toStop[prop]),
48
                            elapsed,
49
                            duration,
50
                            fn
51
                        ));
52
                    }
53
                    else
54
                    {
55
                        stop[prop] = fn(elapsed, NUM(fromStop[prop]), NUM(toStop[prop]) - NUM(fromStop[prop]), duration);
56
                    }
57
                }
58
            }
59
            stops.push(stop);
60
        }
61
        return stops;
62
    },
63
    FILLANDSTROKEBEHAVIOR = {
64
        set: function(anim, att, from, to, elapsed, duration, fn) {
65
            var i,
66
            updated = {},
67
            getUpdatedColorValue = Y.Anim.getUpdatedColorValue,
68
            getUpdatedStops = GETUPDATEDSTOPS;
69
            for(i in to)
70
            {
71
                if(to.hasOwnProperty(i) && i !== TYPE)
72
                {
73
                    switch(i)
74
                    {
75
                        case COLOR :
76
                            updated[i] = getUpdatedColorValue(from[i], to[i], elapsed, duration, fn);
77
                        break;
78
                        case STOPS :
79
                            updated[i] = getUpdatedStops(anim, from[i], to[i], elapsed, duration, fn);
80
                        break;
81
                        default :
82
                            updated[i] = fn(elapsed, NUM(from[i]), NUM(to[i]) - NUM(from[i]), duration);
83
                        break;
84
                    }
85
                }
86
            }
87
            anim._node.set(att, updated);
88
        }
89
    };
90
    Y.Anim.behaviors.fill = FILLANDSTROKEBEHAVIOR;
91
    Y.Anim.behaviors.stroke = FILLANDSTROKEBEHAVIOR;
92
 
93
    Y.Anim.behaviors.transform = {
94
        set: function(anim, att, from, to, elapsed, duration, fn) {
95
            var node = anim._node,
96
                transform = "",
97
                transformTo,
98
                transformFrom,
99
                toArgs,
100
                fromArgs,
101
                i = 0,
102
                j,
103
                argLen,
104
                len;
105
            to = TO;
106
            len = TO.length;
107
            for(; i < len; ++i)
108
            {
109
                toArgs = to[i].concat();
110
                fromArgs = from[i].concat();
111
                transformTo = toArgs.shift();
112
                transformFrom = fromArgs.shift();
113
                argLen = toArgs.length;
114
                transform += transformTo + "(";
115
                for(j = 0; j < argLen; ++j)
116
                {
117
                    transform += fn(elapsed, NUM(fromArgs[j]), NUM(toArgs[j]) - NUM(fromArgs[j]), duration);
118
                    if(j < argLen - 1)
119
                    {
120
                        transform += ", ";
121
                    }
122
                }
123
                transform += ");";
124
            }
125
            if(transform)
126
            {
127
                node.set('transform', transform);
128
            }
129
            node._transform = TOSTRING;
130
        },
131
 
132
        get: function(anim) {
133
            var node = anim._node,
134
                fromMatrix = node.matrix,
135
                toString = anim.get("to").transform,
136
                fromString = node.get("transform"),
137
                toArray = Y.MatrixUtil.getTransformArray(toString),
138
                fromArray = fromString ? Y.MatrixUtil.getTransformArray(fromString) : null,
139
                toMatrix,
140
                i,
141
                len,
142
                transformFunction,
143
                from;
144
            if(toArray)
145
            {
146
                if(!fromArray || fromArray.length < 1)
147
                {
148
                    fromArray = [];
149
                    len = toArray.length;
150
                    for(i = 0; i < len; ++i)
151
                    {
152
                        transformFunction = toArray[i][0];
153
                        fromArray[i] = Y.MatrixUtil.getTransformFunctionArray(transformFunction);
154
                    }
155
                    TO = toArray;
156
                    from = fromArray;
157
                }
158
                else if(Y.MatrixUtil.compareTransformSequence(toArray, fromArray))
159
                {
160
                    TO = toArray;
161
                    from = fromArray;
162
                }
163
                else
164
                {
165
                    toMatrix = new Y.Matrix();
166
                    len = toArray.length;
167
                    for(i = 0; i < len; ++i)
168
                    {
169
                        transformFunction = toArray[i].shift();
170
                        transformFunction = transformFunction === "matrix" ? "multiply" : transformFunction;
171
                        toMatrix[transformFunction].apply(toMatrix, toArray[i]);
172
                    }
173
 
174
                    TO = toMatrix.decompose();
175
                    from = fromMatrix.decompose();
176
                }
177
            }
178
            TOSTRING = toString;
179
            return from;
180
        }
181
    };
182
 
183
 
184
 
185
}, '3.18.1', {"requires": ["anim-base", "anim-easing", "anim-color", "matrix"]});