OLD | NEW |
| (Empty) |
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.g
ithub.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/CONTRI
BUTORS.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/PATEN
TS.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"> | |
12 | |
13 <script> | |
14 | |
15 /** | |
16 * `Polymer.NeonAnimationRunnerBehavior` adds a method to run animations. | |
17 * @polymerBehavior | |
18 */ | |
19 Polymer.NeonAnimationRunnerBehavior = [Polymer.NeonAnimatableBehavior, { | |
20 | |
21 properties: { | |
22 | |
23 _animationMeta: { | |
24 type: Object, | |
25 value: function() { | |
26 return new Polymer.IronMeta({type: 'animation'}); | |
27 } | |
28 }, | |
29 | |
30 _player: { | |
31 type: Object | |
32 } | |
33 | |
34 }, | |
35 | |
36 _configureAnimationEffects: function(allConfigs) { | |
37 var allAnimations = []; | |
38 if (allConfigs.length > 0) { | |
39 for (var config, index = 0; config = allConfigs[index]; index++) { | |
40 var animationConstructor = this._animationMeta.byKey(config.name); | |
41 if (animationConstructor) { | |
42 var animation = animationConstructor && new animationConstructor(); | |
43 var effect = animation.configure(config); | |
44 if (effect) { | |
45 allAnimations.push({ | |
46 animation: animation, | |
47 config: config, | |
48 effect: effect | |
49 }); | |
50 } | |
51 } else { | |
52 console.warn(this.is + ':', config.name, 'not found!'); | |
53 } | |
54 } | |
55 } | |
56 return allAnimations; | |
57 }, | |
58 | |
59 _runAnimationEffects: function(allEffects) { | |
60 return player = document.timeline.play(new GroupEffect(allEffects)); | |
61 }, | |
62 | |
63 _completeAnimations: function(allAnimations) { | |
64 for (var animation, index = 0; animation = allAnimations[index]; index++)
{ | |
65 animation.animation.complete(animation.config); | |
66 } | |
67 }, | |
68 | |
69 /** | |
70 * Plays an animation with an optional `type`. | |
71 */ | |
72 playAnimation: function(type, cookie) { | |
73 var allConfigs = this.getAnimationConfig(type); | |
74 if (!allConfigs) { | |
75 return; | |
76 } | |
77 var allAnimations = this._configureAnimationEffects(allConfigs); | |
78 var allEffects = allAnimations.map(function(animation) { | |
79 return animation.effect; | |
80 }); | |
81 | |
82 if (allEffects.length > 0) { | |
83 this._player = this._runAnimationEffects(allEffects); | |
84 this._player.onfinish = function() { | |
85 this._completeAnimations(allAnimations); | |
86 | |
87 if (this._player) { | |
88 this._player.cancel(); | |
89 this._player = null; | |
90 } | |
91 | |
92 this.fire('neon-animation-finish', cookie, {bubbles: false}); | |
93 }.bind(this); | |
94 | |
95 } else { | |
96 this.fire('neon-animation-finish', cookie, {bubbles: false}); | |
97 } | |
98 }, | |
99 | |
100 /** | |
101 * Cancels the currently running animation. | |
102 */ | |
103 cancelAnimation: function() { | |
104 if (this._player) { | |
105 this._player.cancel(); | |
106 } | |
107 } | |
108 | |
109 }]; | |
110 </script> | |
OLD | NEW |