Skip to content

Commit e27cd1a

Browse files
committed
Merge pull request #421 from suzyh/animation-id
Implement Animation.id
2 parents 43820f9 + 6733744 commit e27cd1a

9 files changed

+43
-16
lines changed

src/animation.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
};
3232

3333
scope.Animation = function(effect) {
34+
this.id = '';
35+
if (effect && effect._id) {
36+
this.id = effect._id;
37+
}
3438
this._sequenceNumber = shared.sequenceNumber++;
3539
this._currentTime = 0;
3640
this._startTime = null;

src/element-animatable.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
// limitations under the License.
1414

1515
(function(scope) {
16-
window.Element.prototype.animate = function(effectInput, timingInput) {
17-
return scope.timeline._play(scope.KeyframeEffect(this, effectInput, timingInput));
16+
window.Element.prototype.animate = function(effectInput, options) {
17+
var id = '';
18+
if (options && options.id) {
19+
id = options.id;
20+
}
21+
return scope.timeline._play(scope.KeyframeEffect(this, effectInput, options, id));
1822
};
1923
})(webAnimations1);

src/group-constructors.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
return node._timing.delay + node.activeDuration + node._timing.endDelay;
1919
}
2020

21-
function constructor(children, timingInput) {
21+
function constructor(children, timingInput, id) {
22+
this._id = id;
2223
this._parent = null;
2324
this.children = children || [];
2425
this._reparent(this.children);
@@ -184,7 +185,7 @@
184185
}
185186
};
186187

187-
var underlyingEffect = new KeyframeEffect(null, [], group._timing);
188+
var underlyingEffect = new KeyframeEffect(null, [], group._timing, group._id);
188189
underlyingEffect.onsample = ticker;
189190
underlyingAnimation = scope.timeline._play(underlyingEffect);
190191
return underlyingAnimation;

src/keyframe-effect-constructor.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
this._frames = shared.normalizeKeyframes(effectInput);
5454
}
5555

56-
scope.KeyframeEffect = function(target, effectInput, timingInput) {
56+
scope.KeyframeEffect = function(target, effectInput, timingInput, id) {
5757
this.target = target;
5858
this._parent = null;
5959

@@ -71,6 +71,7 @@
7171
}
7272
this._keyframes = effectInput;
7373
this.activeDuration = shared.calculateActiveDuration(this._timing);
74+
this._id = id;
7475
return this;
7576
};
7677

@@ -96,7 +97,7 @@
9697
if (typeof this.getFrames() == 'function') {
9798
throw new Error('Cloning custom effects is not supported.');
9899
}
99-
var clone = new KeyframeEffect(this.target, [], shared.cloneTimingInput(this._timingInput));
100+
var clone = new KeyframeEffect(this.target, [], shared.cloneTimingInput(this._timingInput), this._id);
100101
clone._normalizedKeyframes = this._normalizedKeyframes;
101102
clone._keyframes = this._keyframes;
102103
return clone;
@@ -107,8 +108,12 @@
107108
};
108109

109110
var originalElementAnimate = Element.prototype.animate;
110-
Element.prototype.animate = function(effectInput, timing) {
111-
return scope.timeline._play(new scope.KeyframeEffect(this, effectInput, timing));
111+
Element.prototype.animate = function(effectInput, options) {
112+
var id = '';
113+
if (options && options.id) {
114+
id = options.id;
115+
}
116+
return scope.timeline._play(new scope.KeyframeEffect(this, effectInput, options, id));
112117
};
113118

114119
var nullTarget = document.createElementNS('http://www.w3.org/1999/xhtml', 'div');
@@ -119,13 +124,14 @@
119124
if (typeof keyframes == 'function') {
120125
keyframes = [];
121126
}
122-
var timing = keyframeEffect._timingInput;
127+
var options = keyframeEffect._timingInput;
128+
options.id = keyframeEffect._id;
123129
} else {
124130
var target = nullTarget;
125131
var keyframes = [];
126-
var timing = 0;
132+
var options = 0;
127133
}
128-
return originalElementAnimate.apply(target, [keyframes, timing]);
134+
return originalElementAnimate.apply(target, [keyframes, options]);
129135
};
130136

131137
// TODO: Remove this once we remove support for custom KeyframeEffects.

src/keyframe-effect.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
return effectTime;
2929
}
3030

31-
scope.KeyframeEffect = function(target, effectInput, timingInput) {
31+
scope.KeyframeEffect = function(target, effectInput, timingInput, id) {
3232
var effectTime = EffectTime(shared.normalizeTimingInput(timingInput));
3333
var interpolations = scope.convertEffectInput(effectInput);
3434
var timeFraction;
@@ -49,6 +49,7 @@
4949
};
5050
keyframeEffect._isCurrent = effectTime._isCurrent;
5151
keyframeEffect._totalDuration = effectTime._totalDuration;
52+
keyframeEffect._id = id;
5253
return keyframeEffect;
5354
};
5455

src/web-animations-bonus-cancel-events.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
};
4242

4343
var originalElementAnimate = window.Element.prototype.animate;
44-
window.Element.prototype.animate = function(effectInput, timingInput) {
45-
var animation = originalElementAnimate.call(this, effectInput, timingInput);
44+
window.Element.prototype.animate = function(effectInput, options) {
45+
var animation = originalElementAnimate.call(this, effectInput, options);
4646

4747
animation._cancelHandlers = [];
4848
animation.oncancel = null;

src/web-animations-bonus-object-form-keyframes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
}
2727

2828
var originalElementAnimate = window.Element.prototype.animate;
29-
window.Element.prototype.animate = function(effectInput, timingInput) {
29+
window.Element.prototype.animate = function(effectInput, options) {
3030
if (window.Symbol && Symbol.iterator && Array.prototype.from && effectInput[Symbol.iterator]) {
3131
// Handle custom iterables in most browsers by converting to an array
3232
effectInput = Array.from(effectInput);
@@ -36,6 +36,6 @@
3636
effectInput = shared.convertToArrayForm(effectInput);
3737
}
3838

39-
return originalElementAnimate.call(this, effectInput, timingInput);
39+
return originalElementAnimate.call(this, effectInput, options);
4040
};
4141
})(webAnimationsShared);

src/web-animations-next-animation.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
scope.animationsWithPromises = [];
1717

1818
scope.Animation = function(effect, timeline) {
19+
this.id = '';
20+
if (effect && effect._id) {
21+
this.id = effect._id;
22+
}
1923
this.effect = effect;
2024
if (effect) {
2125
effect._animation = this;

test/js/animation.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,4 +543,11 @@ suite('animation', function() {
543543
assert.equal(a.startTime, null);
544544
assert.equal(a.playState, 'pending');
545545
});
546+
test('Animations have optional ID', function() {
547+
tick(100);
548+
var a = document.body.animate([], { duration: 1000 });
549+
assert.equal(a.id, '');
550+
a = document.body.animate([], { duration: 1000, id: 'anim-id' });
551+
assert.equal(a.id, 'anim-id');
552+
});
546553
});

0 commit comments

Comments
 (0)