2 Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
3 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
5 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
6 Code distributed by Google as part of the polymer project is also
7 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9 <link rel=
"import" href=
"../polymer/polymer.html">
10 <link rel=
"import" href=
"../iron-meta/iron-meta.html">
11 <link rel=
"import" href=
"neon-animatable-behavior.html">
16 * `Polymer.NeonAnimationRunnerBehavior` adds a method to run animations.
18 * @polymerBehavior Polymer.NeonAnimationRunnerBehavior
20 Polymer
.NeonAnimationRunnerBehaviorImpl
= {
27 return new Polymer
.IronMeta({type
: 'animation'});
31 /** @type {?Object} */
38 _configureAnimationEffects: function(allConfigs
) {
39 var allAnimations
= [];
40 if (allConfigs
.length
> 0) {
41 for (var config
, index
= 0; config
= allConfigs
[index
]; index
++) {
42 var animationConstructor
= this._animationMeta
.byKey(config
.name
);
43 if (animationConstructor
) {
44 var animation
= animationConstructor
&& new animationConstructor();
45 var effect
= animation
.configure(config
);
54 console
.warn(this.is
+ ':', config
.name
, 'not found!');
61 _runAnimationEffects: function(allEffects
) {
62 return document
.timeline
.play(new GroupEffect(allEffects
));
65 _completeAnimations: function(allAnimations
) {
66 for (var animation
, index
= 0; animation
= allAnimations
[index
]; index
++) {
67 animation
.animation
.complete(animation
.config
);
72 * Plays an animation with an optional `type`.
73 * @param {string=} type
74 * @param {!Object=} cookie
76 playAnimation: function(type
, cookie
) {
77 var allConfigs
= this.getAnimationConfig(type
);
81 var allAnimations
= this._configureAnimationEffects(allConfigs
);
82 var allEffects
= allAnimations
.map(function(animation
) {
83 return animation
.effect
;
86 if (allEffects
.length
> 0) {
87 this._player
= this._runAnimationEffects(allEffects
);
88 this._player
.onfinish = function() {
89 this._completeAnimations(allAnimations
);
92 this._player
.cancel();
96 this.fire('neon-animation-finish', cookie
, {bubbles
: false});
100 this.fire('neon-animation-finish', cookie
, {bubbles
: false});
105 * Cancels the currently running animation.
107 cancelAnimation: function() {
109 this._player
.cancel();
114 /** @polymerBehavior Polymer.NeonAnimationRunnerBehavior */
115 Polymer
.NeonAnimationRunnerBehavior
= [
116 Polymer
.NeonAnimatableBehavior
,
117 Polymer
.NeonAnimationRunnerBehaviorImpl