Skip to content

Commit 0447987

Browse files
committed
Merge pull request #222 from rjwright/AnimationTimingAlwaysAnObject
Animation timing should always be an object
2 parents 0b5c0f6 + 10ddad8 commit 0447987

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

src/animation-constructor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
this.target = target;
3131
// TODO: Make modifications to specified update the underlying player
3232
this._timing = shared.normalizeTimingInput(timingInput);
33-
this.timing = timingInput;
33+
this.timing = shared.makeTiming(timingInput);
3434
// TODO: Make this a live object - will need to separate normalization of
3535
// keyframes into a shared module.
3636
if (typeof effect == 'function')

src/group-constructors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
function constructor(children, timingInput) {
1818
this.children = children || [];
19-
this.timing = timingInput;
2019
this._timing = shared.normalizeTimingInput(timingInput, true);
20+
this.timing = shared.makeTiming(timingInput, true);
2121

2222
if (this._timing.duration === 'auto')
2323
this._timing.duration = this.activeDuration;

src/timing-utilities.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
var fills = 'backwards|forwards|both'.split('|');
1818
var directions = 'reverse|alternate|alternate-reverse'.split('|');
1919

20-
function normalizeTimingInput(timingInput, forGroup) {
20+
function makeTiming(timingInput, forGroup) {
2121
var timing = {
2222
delay: 0,
2323
endDelay: 0,
@@ -29,7 +29,6 @@
2929
direction: 'normal',
3030
easing: 'linear',
3131
};
32-
3332
if (typeof timingInput == 'number') {
3433
timing.duration = timingInput;
3534
} else if (timingInput !== undefined) {
@@ -48,6 +47,11 @@
4847
}
4948
});
5049
}
50+
return timing;
51+
}
52+
53+
function normalizeTimingInput(timingInput, forGroup) {
54+
var timing = makeTiming(timingInput, forGroup);
5155
timing.easing = toTimingFunction(timing.easing);
5256
return timing;
5357
}
@@ -207,6 +211,7 @@
207211
return calculateTransformedTime(currentIteration, timing.duration, iterationTime, timing) / timing.duration;
208212
}
209213

214+
shared.makeTiming = makeTiming;
210215
shared.normalizeTimingInput = normalizeTimingInput;
211216
shared.calculateActiveDuration = calculateActiveDuration;
212217
shared.calculateTimeFraction = calculateTimeFraction;

test/js/animation-constructor.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,20 @@ suite('animation-constructor', function() {
4747
assert.closeTo(leftAsNumber(target2), 15.25, 1);
4848
});
4949

50+
test('Timing is always converted to AnimationTimingInput', function() {
51+
var target = document.createElement('div');
52+
document.body.appendChild(target);
53+
54+
var keyframes = [{background: 'blue'}, {background: 'red'}];
55+
56+
var animation = new Animation(target, keyframes, 200);
57+
assert.equal(animation.timing.duration, 200);
58+
59+
animation = new Animation(target, keyframes);
60+
assert.isDefined(animation.timing);
61+
62+
animation = new Animation(target, keyframes, {duration: 200});
63+
var group = new AnimationGroup([animation]);
64+
assert.equal(group.timing.duration, 'auto');
65+
});
5066
});

0 commit comments

Comments
 (0)