Upgrade to ExtJS 3.3.1 - Released 11/30/2010
[extjs.git] / src / ext-core / src / adapter / ext-base-anim-extra.js
1 /*!
2  * Ext JS Library 3.3.1
3  * Copyright(c) 2006-2010 Sencha Inc.
4  * licensing@sencha.com
5  * http://www.sencha.com/license
6  */
7 // Easing functions
8 (function(){
9     // shortcuts to aid compression
10     var abs = Math.abs,
11         pi = Math.PI,
12         asin = Math.asin,
13         pow = Math.pow,
14         sin = Math.sin,
15         EXTLIB = Ext.lib;
16
17     Ext.apply(EXTLIB.Easing, {
18
19         easeBoth: function (t, b, c, d) {
20             return ((t /= d / 2) < 1)  ?  c / 2 * t * t + b  :  -c / 2 * ((--t) * (t - 2) - 1) + b;
21         },
22
23         easeInStrong: function (t, b, c, d) {
24             return c * (t /= d) * t * t * t + b;
25         },
26
27         easeOutStrong: function (t, b, c, d) {
28             return -c * ((t = t / d - 1) * t * t * t - 1) + b;
29         },
30
31         easeBothStrong: function (t, b, c, d) {
32             return ((t /= d / 2) < 1)  ?  c / 2 * t * t * t * t + b  :  -c / 2 * ((t -= 2) * t * t * t - 2) + b;
33         },
34
35         elasticIn: function (t, b, c, d, a, p) {
36             if (t == 0 || (t /= d) == 1) {
37                 return t == 0 ? b : b + c;
38             }
39             p = p || (d * .3);
40
41             var s;
42             if (a >= abs(c)) {
43                 s = p / (2 * pi) * asin(c / a);
44             } else {
45                 a = c;
46                 s = p / 4;
47             }
48
49             return -(a * pow(2, 10 * (t -= 1)) * sin((t * d - s) * (2 * pi) / p)) + b;
50
51         },
52
53         elasticOut: function (t, b, c, d, a, p) {
54             if (t == 0 || (t /= d) == 1) {
55                 return t == 0 ? b : b + c;
56             }
57             p = p || (d * .3);
58
59             var s;
60             if (a >= abs(c)) {
61                 s = p / (2 * pi) * asin(c / a);
62             } else {
63                 a = c;
64                 s = p / 4;
65             }
66
67             return a * pow(2, -10 * t) * sin((t * d - s) * (2 * pi) / p) + c + b;
68         },
69
70         elasticBoth: function (t, b, c, d, a, p) {
71             if (t == 0 || (t /= d / 2) == 2) {
72                 return t == 0 ? b : b + c;
73             }
74
75             p = p || (d * (.3 * 1.5));
76
77             var s;
78             if (a >= abs(c)) {
79                 s = p / (2 * pi) * asin(c / a);
80             } else {
81                 a = c;
82                 s = p / 4;
83             }
84
85             return t < 1 ?
86                     -.5 * (a * pow(2, 10 * (t -= 1)) * sin((t * d - s) * (2 * pi) / p)) + b :
87                     a * pow(2, -10 * (t -= 1)) * sin((t * d - s) * (2 * pi) / p) * .5 + c + b;
88         },
89
90         backIn: function (t, b, c, d, s) {
91             s = s ||  1.70158;
92             return c * (t /= d) * t * ((s + 1) * t - s) + b;
93         },
94
95
96         backOut: function (t, b, c, d, s) {
97             if (!s) {
98                 s = 1.70158;
99             }
100             return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
101         },
102
103
104         backBoth: function (t, b, c, d, s) {
105             s = s || 1.70158;
106
107             return ((t /= d / 2 ) < 1) ?
108                     c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b :
109                     c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
110         },
111
112
113         bounceIn: function (t, b, c, d) {
114             return c - EXTLIB.Easing.bounceOut(d - t, 0, c, d) + b;
115         },
116
117
118         bounceOut: function (t, b, c, d) {
119         if ((t /= d) < (1 / 2.75)) {
120                 return c * (7.5625 * t * t) + b;
121             } else if (t < (2 / 2.75)) {
122                 return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
123             } else if (t < (2.5 / 2.75)) {
124                 return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
125             }
126             return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
127         },
128
129
130         bounceBoth: function (t, b, c, d) {
131             return (t < d / 2) ?
132                     EXTLIB.Easing.bounceIn(t * 2, 0, c, d) * .5 + b :
133                     EXTLIB.Easing.bounceOut(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
134         }
135     });
136 })();
137
138 (function() {
139     var EXTLIB = Ext.lib;
140     // Color Animation
141     EXTLIB.Anim.color = function(el, args, duration, easing, cb, scope) {
142         return EXTLIB.Anim.run(el, args, duration, easing, cb, scope, EXTLIB.ColorAnim);
143     };
144
145     EXTLIB.ColorAnim = function(el, attributes, duration, method) {
146         EXTLIB.ColorAnim.superclass.constructor.call(this, el, attributes, duration, method);
147     };
148
149     Ext.extend(EXTLIB.ColorAnim, EXTLIB.AnimBase);
150
151     var superclass = EXTLIB.ColorAnim.superclass,
152         colorRE = /color$/i,
153         transparentRE = /^transparent|rgba\(0, 0, 0, 0\)$/,
154         rgbRE = /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i,
155         hexRE= /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i,
156         hex3RE = /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i,
157         isset = function(v){
158             return typeof v !== 'undefined';
159         };
160
161     // private
162     function parseColor(s) {
163         var pi = parseInt,
164             base,
165             out = null,
166             c;
167
168         if (s.length == 3) {
169             return s;
170         }
171
172         Ext.each([hexRE, rgbRE, hex3RE], function(re, idx){
173             base = (idx % 2 == 0) ? 16 : 10;
174             c = re.exec(s);
175             if(c && c.length == 4){
176                 out = [pi(c[1], base), pi(c[2], base), pi(c[3], base)];
177                 return false;
178             }
179         });
180         return out;
181     }
182
183     Ext.apply(EXTLIB.ColorAnim.prototype, {
184         getAttr : function(attr) {
185             var me = this,
186                 el = me.el,
187                 val;
188             if(colorRE.test(attr)){
189                 while(el && transparentRE.test(val = Ext.fly(el).getStyle(attr))){
190                     el = el.parentNode;
191                     val = "fff";
192                 }
193             }else{
194                 val = superclass.getAttr.call(me, attr);
195             }
196             return val;
197         },
198
199         doMethod : function(attr, start, end) {
200             var me = this,
201                 val,
202                 floor = Math.floor,
203                 i,
204                 len,
205                 v;
206
207             if(colorRE.test(attr)){
208                 val = [];
209                 end = end || [];
210
211                 for(i = 0, len = start.length; i < len; i++) {
212                     v = start[i];
213                     val[i] = superclass.doMethod.call(me, attr, v, end[i]);
214                 }
215                 val = 'rgb(' + floor(val[0]) + ',' + floor(val[1]) + ',' + floor(val[2]) + ')';
216             }else{
217                 val = superclass.doMethod.call(me, attr, start, end);
218             }
219             return val;
220         },
221
222         setRunAttr : function(attr) {
223             var me = this,
224                 a = me.attributes[attr],
225                 to = a.to,
226                 by = a.by,
227                 ra;
228
229             superclass.setRunAttr.call(me, attr);
230             ra = me.runAttrs[attr];
231             if(colorRE.test(attr)){
232                 var start = parseColor(ra.start),
233                     end = parseColor(ra.end);
234
235                 if(!isset(to) && isset(by)){
236                     end = parseColor(by);
237                     for(var i=0,len=start.length; i<len; i++) {
238                         end[i] = start[i] + end[i];
239                     }
240                 }
241                 ra.start = start;
242                 ra.end = end;
243             }
244         }
245     });
246 })();
247
248
249 (function() {
250     // Scroll Animation
251     var EXTLIB = Ext.lib;
252     EXTLIB.Anim.scroll = function(el, args, duration, easing, cb, scope) {
253         return EXTLIB.Anim.run(el, args, duration, easing, cb, scope, EXTLIB.Scroll);
254     };
255
256     EXTLIB.Scroll = function(el, attributes, duration, method) {
257         if(el){
258             EXTLIB.Scroll.superclass.constructor.call(this, el, attributes, duration, method);
259         }
260     };
261
262     Ext.extend(EXTLIB.Scroll, EXTLIB.ColorAnim);
263
264     var superclass = EXTLIB.Scroll.superclass,
265         SCROLL = 'scroll';
266
267     Ext.apply(EXTLIB.Scroll.prototype, {
268
269         doMethod : function(attr, start, end) {
270             var val,
271                 me = this,
272                 curFrame = me.curFrame,
273                 totalFrames = me.totalFrames;
274
275             if(attr == SCROLL){
276                 val = [me.method(curFrame, start[0], end[0] - start[0], totalFrames),
277                        me.method(curFrame, start[1], end[1] - start[1], totalFrames)];
278             }else{
279                 val = superclass.doMethod.call(me, attr, start, end);
280             }
281             return val;
282         },
283
284         getAttr : function(attr) {
285             var me = this;
286
287             if (attr == SCROLL) {
288                 return [me.el.scrollLeft, me.el.scrollTop];
289             }else{
290                 return superclass.getAttr.call(me, attr);
291             }
292         },
293
294         setAttr : function(attr, val, unit) {
295             var me = this;
296
297             if(attr == SCROLL){
298                 me.el.scrollLeft = val[0];
299                 me.el.scrollTop = val[1];
300             }else{
301                 superclass.setAttr.call(me, attr, val, unit);
302             }
303         }
304     });
305 })();