]> git.wh0rd.org - tt-rss.git/blame - lib/dojo/fx/easing.js
remove call-by-reference to comply with php 5.4
[tt-rss.git] / lib / dojo / fx / easing.js
CommitLineData
2f01fe57 1/*
81bea17a 2 Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
2f01fe57
AD
3 Available via Academic Free License >= 2.1 OR the modified BSD license.
4 see: http://dojotoolkit.org/license for details
5*/
6
7
a089699c
AD
8if(!dojo._hasResource["dojo.fx.easing"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
9dojo._hasResource["dojo.fx.easing"] = true;
2f01fe57 10dojo.provide("dojo.fx.easing");
a089699c 11
81bea17a
AD
12dojo.getObject("fx.easing", true, dojo);
13
a089699c 14dojo.fx.easing = {
81bea17a
AD
15 // summary:
16 // Collection of easing functions to use beyond the default
a089699c 17 // `dojo._defaultEasing` function.
81bea17a 18 //
a089699c
AD
19 // description:
20 //
21 // Easing functions are used to manipulate the iteration through
22 // an `dojo.Animation`s _Line. _Line being the properties of an Animation,
23 // and the easing function progresses through that Line determing
24 // how quickly (or slowly) it should go. Or more accurately: modify
25 // the value of the _Line based on the percentage of animation completed.
81bea17a 26 //
a089699c
AD
27 // All functions follow a simple naming convention of "ease type" + "when".
28 // If the name of the function ends in Out, the easing described appears
29 // towards the end of the animation. "In" means during the beginning,
30 // and InOut means both ranges of the Animation will applied, both
81bea17a 31 // beginning and end.
a089699c 32 //
81bea17a 33 // One does not call the easing function directly, it must be passed to
a089699c
AD
34 // the `easing` property of an animation.
35 //
36 // example:
37 // | dojo.require("dojo.fx.easing");
38 // | var anim = dojo.fadeOut({
81bea17a 39 // | node: 'node',
a089699c 40 // | duration: 2000,
81bea17a 41 // | // note there is no ()
a089699c
AD
42 // | easing: dojo.fx.easing.quadIn
43 // | }).play();
44 //
45
46 linear: function(/* Decimal? */n){
47 // summary: A linear easing function
48 return n;
49 },
50
51 quadIn: function(/* Decimal? */n){
52 return Math.pow(n, 2);
53 },
54
55 quadOut: function(/* Decimal? */n){
56 return n * (n - 2) * -1;
57 },
58
59 quadInOut: function(/* Decimal? */n){
60 n = n * 2;
61 if(n < 1){ return Math.pow(n, 2) / 2; }
62 return -1 * ((--n) * (n - 2) - 1) / 2;
63 },
64
65 cubicIn: function(/* Decimal? */n){
66 return Math.pow(n, 3);
67 },
68
69 cubicOut: function(/* Decimal? */n){
70 return Math.pow(n - 1, 3) + 1;
71 },
72
73 cubicInOut: function(/* Decimal? */n){
74 n = n * 2;
75 if(n < 1){ return Math.pow(n, 3) / 2; }
76 n -= 2;
77 return (Math.pow(n, 3) + 2) / 2;
78 },
79
80 quartIn: function(/* Decimal? */n){
81 return Math.pow(n, 4);
82 },
83
84 quartOut: function(/* Decimal? */n){
85 return -1 * (Math.pow(n - 1, 4) - 1);
86 },
87
88 quartInOut: function(/* Decimal? */n){
89 n = n * 2;
90 if(n < 1){ return Math.pow(n, 4) / 2; }
91 n -= 2;
92 return -1 / 2 * (Math.pow(n, 4) - 2);
93 },
94
95 quintIn: function(/* Decimal? */n){
96 return Math.pow(n, 5);
97 },
98
99 quintOut: function(/* Decimal? */n){
100 return Math.pow(n - 1, 5) + 1;
101 },
102
103 quintInOut: function(/* Decimal? */n){
104 n = n * 2;
105 if(n < 1){ return Math.pow(n, 5) / 2; };
106 n -= 2;
107 return (Math.pow(n, 5) + 2) / 2;
108 },
109
110 sineIn: function(/* Decimal? */n){
111 return -1 * Math.cos(n * (Math.PI / 2)) + 1;
112 },
113
114 sineOut: function(/* Decimal? */n){
115 return Math.sin(n * (Math.PI / 2));
116 },
117
118 sineInOut: function(/* Decimal? */n){
119 return -1 * (Math.cos(Math.PI * n) - 1) / 2;
120 },
121
122 expoIn: function(/* Decimal? */n){
123 return (n == 0) ? 0 : Math.pow(2, 10 * (n - 1));
124 },
125
126 expoOut: function(/* Decimal? */n){
127 return (n == 1) ? 1 : (-1 * Math.pow(2, -10 * n) + 1);
128 },
129
130 expoInOut: function(/* Decimal? */n){
131 if(n == 0){ return 0; }
132 if(n == 1){ return 1; }
133 n = n * 2;
134 if(n < 1){ return Math.pow(2, 10 * (n - 1)) / 2; }
135 --n;
136 return (-1 * Math.pow(2, -10 * n) + 2) / 2;
137 },
138
139 circIn: function(/* Decimal? */n){
140 return -1 * (Math.sqrt(1 - Math.pow(n, 2)) - 1);
141 },
142
143 circOut: function(/* Decimal? */n){
144 n = n - 1;
145 return Math.sqrt(1 - Math.pow(n, 2));
146 },
147
148 circInOut: function(/* Decimal? */n){
149 n = n * 2;
150 if(n < 1){ return -1 / 2 * (Math.sqrt(1 - Math.pow(n, 2)) - 1); }
151 n -= 2;
152 return 1 / 2 * (Math.sqrt(1 - Math.pow(n, 2)) + 1);
153 },
154
155 backIn: function(/* Decimal? */n){
81bea17a
AD
156 // summary:
157 // An easing function that starts away from the target,
a089699c 158 // and quickly accelerates towards the end value.
81bea17a
AD
159 //
160 // Use caution when the easing will cause values to become
a089699c
AD
161 // negative as some properties cannot be set to negative values.
162 var s = 1.70158;
163 return Math.pow(n, 2) * ((s + 1) * n - s);
164 },
165
166 backOut: function(/* Decimal? */n){
81bea17a
AD
167 // summary:
168 // An easing function that pops past the range briefly, and slowly comes back.
a089699c
AD
169 //
170 // description:
81bea17a 171 // An easing function that pops past the range briefly, and slowly comes back.
a089699c 172 //
81bea17a 173 // Use caution when the easing will cause values to become negative as some
a089699c
AD
174 // properties cannot be set to negative values.
175
176 n = n - 1;
177 var s = 1.70158;
178 return Math.pow(n, 2) * ((s + 1) * n + s) + 1;
179 },
180
181 backInOut: function(/* Decimal? */n){
81bea17a 182 // summary:
a089699c
AD
183 // An easing function combining the effects of `backIn` and `backOut`
184 //
185 // description:
186 // An easing function combining the effects of `backIn` and `backOut`.
81bea17a 187 // Use caution when the easing will cause values to become negative
a089699c
AD
188 // as some properties cannot be set to negative values.
189 var s = 1.70158 * 1.525;
190 n = n * 2;
191 if(n < 1){ return (Math.pow(n, 2) * ((s + 1) * n - s)) / 2; }
192 n-=2;
193 return (Math.pow(n, 2) * ((s + 1) * n + s) + 2) / 2;
194 },
195
196 elasticIn: function(/* Decimal? */n){
81bea17a 197 // summary:
a089699c
AD
198 // An easing function the elastically snaps from the start value
199 //
200 // description:
201 // An easing function the elastically snaps from the start value
81bea17a
AD
202 //
203 // Use caution when the elasticity will cause values to become negative
a089699c
AD
204 // as some properties cannot be set to negative values.
205 if(n == 0 || n == 1){ return n; }
206 var p = .3;
207 var s = p / 4;
208 n = n - 1;
209 return -1 * Math.pow(2, 10 * n) * Math.sin((n - s) * (2 * Math.PI) / p);
210 },
211
212 elasticOut: function(/* Decimal? */n){
81bea17a 213 // summary:
a089699c
AD
214 // An easing function that elasticly snaps around the target value,
215 // near the end of the Animation
216 //
217 // description:
218 // An easing function that elasticly snaps around the target value,
219 // near the end of the Animation
220 //
81bea17a 221 // Use caution when the elasticity will cause values to become
a089699c
AD
222 // negative as some properties cannot be set to negative values.
223 if(n==0 || n == 1){ return n; }
224 var p = .3;
225 var s = p / 4;
226 return Math.pow(2, -10 * n) * Math.sin((n - s) * (2 * Math.PI) / p) + 1;
227 },
228
229 elasticInOut: function(/* Decimal? */n){
81bea17a 230 // summary:
a089699c
AD
231 // An easing function that elasticly snaps around the value, near
232 // the beginning and end of the Animation.
233 //
234 // description:
235 // An easing function that elasticly snaps around the value, near
236 // the beginning and end of the Animation.
237 //
81bea17a 238 // Use caution when the elasticity will cause values to become
a089699c
AD
239 // negative as some properties cannot be set to negative values.
240 if(n == 0) return 0;
241 n = n * 2;
242 if(n == 2) return 1;
243 var p = .3 * 1.5;
244 var s = p / 4;
245 if(n < 1){
246 n -= 1;
247 return -.5 * (Math.pow(2, 10 * n) * Math.sin((n - s) * (2 * Math.PI) / p));
248 }
249 n -= 1;
250 return .5 * (Math.pow(2, -10 * n) * Math.sin((n - s) * (2 * Math.PI) / p)) + 1;
251 },
252
253 bounceIn: function(/* Decimal? */n){
81bea17a 254 // summary:
a089699c
AD
255 // An easing function that 'bounces' near the beginning of an Animation
256 return (1 - dojo.fx.easing.bounceOut(1 - n)); // Decimal
257 },
258
259 bounceOut: function(/* Decimal? */n){
260 // summary:
261 // An easing function that 'bounces' near the end of an Animation
262 var s = 7.5625;
263 var p = 2.75;
81bea17a 264 var l;
a089699c
AD
265 if(n < (1 / p)){
266 l = s * Math.pow(n, 2);
267 }else if(n < (2 / p)){
268 n -= (1.5 / p);
269 l = s * Math.pow(n, 2) + .75;
270 }else if(n < (2.5 / p)){
271 n -= (2.25 / p);
272 l = s * Math.pow(n, 2) + .9375;
273 }else{
274 n -= (2.625 / p);
275 l = s * Math.pow(n, 2) + .984375;
276 }
277 return l;
278 },
279
280 bounceInOut: function(/* Decimal? */n){
81bea17a 281 // summary:
a089699c
AD
282 // An easing function that 'bounces' at the beginning and end of the Animation
283 if(n < 0.5){ return dojo.fx.easing.bounceIn(n * 2) / 2; }
284 return (dojo.fx.easing.bounceOut(n * 2 - 1) / 2) + 0.5; // Decimal
285 }
286};
287
2f01fe57 288}