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