ApplicationImpl cleanup, part 1:
[chromium-blink-merge.git] / third_party / polymer / v1_0 / components-chromium / neon-animation / neon-animation-runner-behavior-extracted.js
blob1c06f05e3ccb4b1a3adf24e072977df92cce9945
3 /**
4 * `Polymer.NeonAnimationRunnerBehavior` adds a method to run animations.
6 * @polymerBehavior Polymer.NeonAnimationRunnerBehavior
7 */
8 Polymer.NeonAnimationRunnerBehaviorImpl = {
10 properties: {
12 _animationMeta: {
13 type: Object,
14 value: function() {
15 return new Polymer.IronMeta({type: 'animation'});
19 /** @type {?Object} */
20 _player: {
21 type: Object
26 _configureAnimationEffects: function(allConfigs) {
27 var allAnimations = [];
28 if (allConfigs.length > 0) {
29 for (var config, index = 0; config = allConfigs[index]; index++) {
30 var animationConstructor = this._animationMeta.byKey(config.name);
31 if (animationConstructor) {
32 var animation = animationConstructor && new animationConstructor();
33 var effect = animation.configure(config);
34 if (effect) {
35 allAnimations.push({
36 animation: animation,
37 config: config,
38 effect: effect
39 });
41 } else {
42 console.warn(this.is + ':', config.name, 'not found!');
46 return allAnimations;
49 _runAnimationEffects: function(allEffects) {
50 return document.timeline.play(new GroupEffect(allEffects));
53 _completeAnimations: function(allAnimations) {
54 for (var animation, index = 0; animation = allAnimations[index]; index++) {
55 animation.animation.complete(animation.config);
59 /**
60 * Plays an animation with an optional `type`.
61 * @param {string=} type
62 * @param {!Object=} cookie
64 playAnimation: function(type, cookie) {
65 var allConfigs = this.getAnimationConfig(type);
66 if (!allConfigs) {
67 return;
69 var allAnimations = this._configureAnimationEffects(allConfigs);
70 var allEffects = allAnimations.map(function(animation) {
71 return animation.effect;
72 });
74 if (allEffects.length > 0) {
75 this._player = this._runAnimationEffects(allEffects);
76 this._player.onfinish = function() {
77 this._completeAnimations(allAnimations);
79 if (this._player) {
80 this._player.cancel();
81 this._player = null;
84 this.fire('neon-animation-finish', cookie, {bubbles: false});
85 }.bind(this);
87 } else {
88 this.fire('neon-animation-finish', cookie, {bubbles: false});
92 /**
93 * Cancels the currently running animation.
95 cancelAnimation: function() {
96 if (this._player) {
97 this._player.cancel();
102 /** @polymerBehavior Polymer.NeonAnimationRunnerBehavior */
103 Polymer.NeonAnimationRunnerBehavior = [
104 Polymer.NeonAnimatableBehavior,
105 Polymer.NeonAnimationRunnerBehaviorImpl