Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / third_party / polymer / v1_0 / components / neon-animation / neon-animation-runner-behavior.html
blobbed94fc8fbe06b08a851908b6c068880e7f0cc32
1 <!--
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
8 -->
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">
13 <script>
15 /**
16 * `Polymer.NeonAnimationRunnerBehavior` adds a method to run animations.
18 * @polymerBehavior Polymer.NeonAnimationRunnerBehavior
20 Polymer.NeonAnimationRunnerBehaviorImpl = {
22 properties: {
24 _animationMeta: {
25 type: Object,
26 value: function() {
27 return new Polymer.IronMeta({type: 'animation'});
31 /** @type {?Object} */
32 _player: {
33 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);
46 if (effect) {
47 allAnimations.push({
48 animation: animation,
49 config: config,
50 effect: effect
51 });
53 } else {
54 console.warn(this.is + ':', config.name, 'not found!');
58 return allAnimations;
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);
71 /**
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);
78 if (!allConfigs) {
79 return;
81 var allAnimations = this._configureAnimationEffects(allConfigs);
82 var allEffects = allAnimations.map(function(animation) {
83 return animation.effect;
84 });
86 if (allEffects.length > 0) {
87 this._player = this._runAnimationEffects(allEffects);
88 this._player.onfinish = function() {
89 this._completeAnimations(allAnimations);
91 if (this._player) {
92 this._player.cancel();
93 this._player = null;
96 this.fire('neon-animation-finish', cookie, {bubbles: false});
97 }.bind(this);
99 } else {
100 this.fire('neon-animation-finish', cookie, {bubbles: false});
105 * Cancels the currently running animation.
107 cancelAnimation: function() {
108 if (this._player) {
109 this._player.cancel();
114 /** @polymerBehavior Polymer.NeonAnimationRunnerBehavior */
115 Polymer.NeonAnimationRunnerBehavior = [
116 Polymer.NeonAnimatableBehavior,
117 Polymer.NeonAnimationRunnerBehaviorImpl
119 </script>