3
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
4
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7
Code distributed by Google as part of the polymer project is also
8
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
11
<link rel="import" href="../polymer/polymer.html">
12
<link rel="import" href="animations/opaque-animation.html">
17
* `Polymer.NeonAnimatableBehavior` is implemented by elements containing animations for use with
18
* elements implementing `Polymer.NeonAnimationRunnerBehavior`.
21
Polymer.NeonAnimatableBehavior = {
26
* Animation configuration. See README for more info.
33
* Convenience property for setting an 'entry' animation. Do not set `animationConfig.entry`
34
* manually if using this. The animated node is set to `this` if using this property.
37
observer: '_entryAnimationChanged',
42
* Convenience property for setting an 'exit' animation. Do not set `animationConfig.exit`
43
* manually if using this. The animated node is set to `this` if using this property.
46
observer: '_exitAnimationChanged',
52
_entryAnimationChanged: function() {
53
this.animationConfig = this.animationConfig || {};
54
if (this.entryAnimation !== 'fade-in-animation') {
55
// insert polyfill hack
56
this.animationConfig['entry'] = [{
57
name: 'opaque-animation',
60
name: this.entryAnimation,
64
this.animationConfig['entry'] = [{
65
name: this.entryAnimation,
71
_exitAnimationChanged: function() {
72
this.animationConfig = this.animationConfig || {};
73
this.animationConfig['exit'] = [{
74
name: this.exitAnimation,
79
_copyProperties: function(config1, config2) {
80
// shallowly copy properties from config2 to config1
81
for (var property in config2) {
82
config1[property] = config2[property];
86
_cloneConfig: function(config) {
90
this._copyProperties(clone, config);
94
_getAnimationConfigRecursive: function(type, map, allConfigs) {
95
if (!this.animationConfig) {
99
if(this.animationConfig.value && typeof this.animationConfig.value === 'function') {
100
this._warn(this._logf('playAnimation', "Please put 'animationConfig' inside of your components 'properties' object instead of outside of it."));
107
thisConfig = this.animationConfig[type];
109
thisConfig = this.animationConfig;
112
if (!Array.isArray(thisConfig)) {
113
thisConfig = [thisConfig];
116
// iterate animations and recurse to process configurations from child nodes
118
for (var config, index = 0; config = thisConfig[index]; index++) {
119
if (config.animatable) {
120
config.animatable._getAnimationConfigRecursive(config.type || type, map, allConfigs);
123
var cachedConfig = map[config.id];
125
// merge configurations with the same id, making a clone lazily
126
if (!cachedConfig.isClone) {
127
map[config.id] = this._cloneConfig(cachedConfig)
128
cachedConfig = map[config.id];
130
this._copyProperties(cachedConfig, config);
132
// put any configs with an id into a map
133
map[config.id] = config;
136
allConfigs.push(config);
144
* An element implementing `Polymer.NeonAnimationRunnerBehavior` calls this method to configure
145
* an animation with an optional type. Elements implementing `Polymer.NeonAnimatableBehavior`
146
* should define the property `animationConfig`, which is either a configuration object
147
* or a map of animation type to array of configuration objects.
149
getAnimationConfig: function(type) {
152
this._getAnimationConfigRecursive(type, map, allConfigs);
153
// append the configurations saved in the map to the array
154
for (var key in map) {
155
allConfigs.push(map[key]);