| 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 * | |
| 18 * @polymerBehavior Polymer.NeonAnimationRunnerBehavior | |
| 19 */ | |
| 20 Polymer.NeonAnimationRunnerBehaviorImpl = { | |
| 21 | |
| 22 properties: { | |
| 23 | |
| 24 _animationMeta: { | |
| 25 type: Object, | |
| 26 value: function() { | |
| 27 return new Polymer.IronMeta({type: 'animation'}); | |
| 28 } | |
| 29 }, | |
| 30 | |
| 31 /** @type {?Object} */ | |
| 32 _player: { | |
| 33 type: Object | |
| 34 } | |
| 35 | |
| 36 }, | |
| 37 | |
| 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 }); | |
| 52 } | |
| 53 } else { | |
| 54 console.warn(this.is + ':', config.name, 'not found!'); | |
| 55 } | |
| 56 } | |
| 57 } | |
| 58 return allAnimations; | |
| 59 }, | |
| 60 | |
| 61 _runAnimationEffects: function(allEffects) { | |
| 62 return document.timeline.play(new GroupEffect(allEffects)); | |
| 63 }, | |
| 64 | |
| 65 _completeAnimations: function(allAnimations) { | |
| 66 for (var animation, index = 0; animation = allAnimations[index]; index++)
{ | |
| 67 animation.animation.complete(animation.config); | |
| 68 } | |
| 69 }, | |
| 70 | |
| 71 /** | |
| 72 * Plays an animation with an optional `type`. | |
| 73 * @param {string=} type | |
| 74 * @param {!Object=} cookie | |
| 75 */ | |
| 76 playAnimation: function(type, cookie) { | |
| 77 var allConfigs = this.getAnimationConfig(type); | |
| 78 if (!allConfigs) { | |
| 79 return; | |
| 80 } | |
| 81 var allAnimations = this._configureAnimationEffects(allConfigs); | |
| 82 var allEffects = allAnimations.map(function(animation) { | |
| 83 return animation.effect; | |
| 84 }); | |
| 85 | |
| 86 if (allEffects.length > 0) { | |
| 87 this._player = this._runAnimationEffects(allEffects); | |
| 88 this._player.onfinish = function() { | |
| 89 this._completeAnimations(allAnimations); | |
| 90 | |
| 91 if (this._player) { | |
| 92 this._player.cancel(); | |
| 93 this._player = null; | |
| 94 } | |
| 95 | |
| 96 this.fire('neon-animation-finish', cookie, {bubbles: false}); | |
| 97 }.bind(this); | |
| 98 | |
| 99 } else { | |
| 100 this.fire('neon-animation-finish', cookie, {bubbles: false}); | |
| 101 } | |
| 102 }, | |
| 103 | |
| 104 /** | |
| 105 * Cancels the currently running animation. | |
| 106 */ | |
| 107 cancelAnimation: function() { | |
| 108 if (this._player) { | |
| 109 this._player.cancel(); | |
| 110 } | |
| 111 } | |
| 112 }; | |
| 113 | |
| 114 /** @polymerBehavior Polymer.NeonAnimationRunnerBehavior */ | |
| 115 Polymer.NeonAnimationRunnerBehavior = [ | |
| 116 Polymer.NeonAnimatableBehavior, | |
| 117 Polymer.NeonAnimationRunnerBehaviorImpl | |
| 118 ]; | |
| 119 </script> | |
| OLD | NEW |