Merge pull request #2573 from kentaromiura/no-sniff-2-of-3-oldie-clonenode-bug
[mootools.git] / Source / Fx / Fx.Transitions.js
blobd9fc6b7a831ac57fd1b3edc791efe8603ad6a613
1 /*
2 ---
4 name: Fx.Transitions
6 description: Contains a set of advanced transitions to be used with any of the Fx Classes.
8 license: MIT-style license.
10 credits:
11   - Easing Equations by Robert Penner, <http://www.robertpenner.com/easing/>, modified and optimized to be used with MooTools.
13 requires: Fx
15 provides: Fx.Transitions
17 ...
20 Fx.implement({
22         getTransition: function(){
23                 var trans = this.options.transition || Fx.Transitions.Sine.easeInOut;
24                 if (typeof trans == 'string'){
25                         var data = trans.split(':');
26                         trans = Fx.Transitions;
27                         trans = trans[data[0]] || trans[data[0].capitalize()];
28                         if (data[1]) trans = trans['ease' + data[1].capitalize() + (data[2] ? data[2].capitalize() : '')];
29                 }
30                 return trans;
31         }
33 });
35 Fx.Transition = function(transition, params){
36         params = Array.from(params);
37         var easeIn = function(pos){
38                 return transition(pos, params);
39         };
40         return Object.append(easeIn, {
41                 easeIn: easeIn,
42                 easeOut: function(pos){
43                         return 1 - transition(1 - pos, params);
44                 },
45                 easeInOut: function(pos){
46                         return (pos <= 0.5 ? transition(2 * pos, params) : (2 - transition(2 * (1 - pos), params))) / 2;
47                 }
48         });
51 Fx.Transitions = {
53         linear: function(zero){
54                 return zero;
55         }
59 //<1.2compat>
61 Fx.Transitions = new Hash(Fx.Transitions);
63 //</1.2compat>
65 Fx.Transitions.extend = function(transitions){
66         for (var transition in transitions) Fx.Transitions[transition] = new Fx.Transition(transitions[transition]);
69 Fx.Transitions.extend({
71         Pow: function(p, x){
72                 return Math.pow(p, x && x[0] || 6);
73         },
75         Expo: function(p){
76                 return Math.pow(2, 8 * (p - 1));
77         },
79         Circ: function(p){
80                 return 1 - Math.sin(Math.acos(p));
81         },
83         Sine: function(p){
84                 return 1 - Math.cos(p * Math.PI / 2);
85         },
87         Back: function(p, x){
88                 x = x && x[0] || 1.618;
89                 return Math.pow(p, 2) * ((x + 1) * p - x);
90         },
92         Bounce: function(p){
93                 var value;
94                 for (var a = 0, b = 1; 1; a += b, b /= 2){
95                         if (p >= (7 - 4 * a) / 11){
96                                 value = b * b - Math.pow((11 - 6 * a - 11 * p) / 4, 2);
97                                 break;
98                         }
99                 }
100                 return value;
101         },
103         Elastic: function(p, x){
104                 return Math.pow(2, 10 * --p) * Math.cos(20 * p * Math.PI * (x && x[0] || 1) / 3);
105         }
109 ['Quad', 'Cubic', 'Quart', 'Quint'].each(function(transition, i){
110         Fx.Transitions[transition] = new Fx.Transition(function(p){
111                 return Math.pow(p, i + 2);
112         });