Skip to content

Commit 594d75c

Browse files
committed
Much more flexible in allowing the ease string input format
1 parent f792f13 commit 594d75c

1 file changed

Lines changed: 42 additions & 2 deletions

File tree

src/tweens/builders/GetEaseFunction.js

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
var EaseMap = require('../../math/easing/EaseMap');
8+
var UppercaseFirst = require('../../utils/string/UppercaseFirst');
89

910
/**
1011
* This internal function is used to return the correct ease function for a Tween.
@@ -25,10 +26,49 @@ var GetEaseFunction = function (ease, easeParams)
2526
var easeFunction = EaseMap.Power0;
2627

2728
// Prepare ease function
28-
if (typeof ease === 'string' && EaseMap.hasOwnProperty(ease))
29+
if (typeof ease === 'string')
2930
{
3031
// String based look-up
31-
easeFunction = EaseMap[ease];
32+
33+
// 1) They specified it correctly
34+
if (EaseMap.hasOwnProperty(ease))
35+
{
36+
easeFunction = EaseMap[ease];
37+
}
38+
else
39+
{
40+
// Do some string manipulation to try and find it
41+
var direction = '';
42+
43+
if (ease.indexOf('.'))
44+
{
45+
// quad.in = Quad.easeIn
46+
// quad.out = Quad.easeOut
47+
// quad.inout =Quad.easeInOut
48+
49+
direction = ease.substr(ease.indexOf('.') + 1);
50+
51+
if (direction.toLowerCase() === 'in')
52+
{
53+
direction = 'easeIn';
54+
}
55+
else if (direction.toLowerCase() === 'out')
56+
{
57+
direction = 'easeOut';
58+
}
59+
else if (direction.toLowerCase() === 'inout')
60+
{
61+
direction = 'easeInOut';
62+
}
63+
}
64+
65+
ease = UppercaseFirst(ease.substr(0, ease.indexOf('.') + 1) + direction);
66+
67+
if (EaseMap.hasOwnProperty(ease))
68+
{
69+
easeFunction = EaseMap[ease];
70+
}
71+
}
3272
}
3373
else if (typeof ease === 'function')
3474
{

0 commit comments

Comments
 (0)