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