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 /** @type {?Object} */ |
| 31 _player: { |
| 32 type: Object |
| 33 } |
| 34 |
| 35 }, |
| 36 |
| 37 _configureAnimationEffects: function(allConfigs) { |
| 38 var allAnimations = []; |
| 39 if (allConfigs.length > 0) { |
| 40 for (var config, index = 0; config = allConfigs[index]; index++) { |
| 41 var animationConstructor = this._animationMeta.byKey(config.name); |
| 42 if (animationConstructor) { |
| 43 var animation = animationConstructor && new animationConstructor(); |
| 44 var effect = animation.configure(config); |
| 45 if (effect) { |
| 46 allAnimations.push({ |
| 47 animation: animation, |
| 48 config: config, |
| 49 effect: effect |
| 50 }); |
| 51 } |
| 52 } else { |
| 53 console.warn(this.is + ':', config.name, 'not found!'); |
| 54 } |
| 55 } |
| 56 } |
| 57 return allAnimations; |
| 58 }, |
| 59 |
| 60 _runAnimationEffects: function(allEffects) { |
| 61 return document.timeline.play(new GroupEffect(allEffects)); |
| 62 }, |
| 63 |
| 64 _completeAnimations: function(allAnimations) { |
| 65 for (var animation, index = 0; animation = allAnimations[index]; index++)
{ |
| 66 animation.animation.complete(animation.config); |
| 67 } |
| 68 }, |
| 69 |
| 70 /** |
| 71 * Plays an animation with an optional `type`. |
| 72 * @param {string=} type |
| 73 * @param {!Object=} cookie |
| 74 */ |
| 75 playAnimation: function(type, cookie) { |
| 76 var allConfigs = this.getAnimationConfig(type); |
| 77 if (!allConfigs) { |
| 78 return; |
| 79 } |
| 80 var allAnimations = this._configureAnimationEffects(allConfigs); |
| 81 var allEffects = allAnimations.map(function(animation) { |
| 82 return animation.effect; |
| 83 }); |
| 84 |
| 85 if (allEffects.length > 0) { |
| 86 this._player = this._runAnimationEffects(allEffects); |
| 87 this._player.onfinish = function() { |
| 88 this._completeAnimations(allAnimations); |
| 89 |
| 90 if (this._player) { |
| 91 this._player.cancel(); |
| 92 this._player = null; |
| 93 } |
| 94 |
| 95 this.fire('neon-animation-finish', cookie, {bubbles: false}); |
| 96 }.bind(this); |
| 97 |
| 98 } else { |
| 99 this.fire('neon-animation-finish', cookie, {bubbles: false}); |
| 100 } |
| 101 }, |
| 102 |
| 103 /** |
| 104 * Cancels the currently running animation. |
| 105 */ |
| 106 cancelAnimation: function() { |
| 107 if (this._player) { |
| 108 this._player.cancel(); |
| 109 } |
| 110 } |
| 111 |
| 112 }]; |
| 113 </script> |
OLD | NEW |