4 * `Polymer.NeonAnimatableBehavior` is implemented by elements containing animations for use with
5 * elements implementing `Polymer.NeonAnimationRunnerBehavior`.
8 Polymer
.NeonAnimatableBehavior
= {
13 * Animation configuration. See README for more info.
20 * Convenience property for setting an 'entry' animation. Do not set `animationConfig.entry`
21 * manually if using this. The animated node is set to `this` if using this property.
24 observer
: '_entryAnimationChanged',
29 * Convenience property for setting an 'exit' animation. Do not set `animationConfig.exit`
30 * manually if using this. The animated node is set to `this` if using this property.
33 observer
: '_exitAnimationChanged',
39 _entryAnimationChanged: function() {
40 this.animationConfig
= this.animationConfig
|| {};
41 if (this.entryAnimation
!== 'fade-in-animation') {
42 // insert polyfill hack
43 this.animationConfig
['entry'] = [{
44 name
: 'opaque-animation',
47 name
: this.entryAnimation
,
51 this.animationConfig
['entry'] = [{
52 name
: this.entryAnimation
,
58 _exitAnimationChanged: function() {
59 this.animationConfig
= this.animationConfig
|| {};
60 this.animationConfig
['exit'] = [{
61 name
: this.exitAnimation
,
66 _copyProperties: function(config1
, config2
) {
67 // shallowly copy properties from config2 to config1
68 for (var property
in config2
) {
69 config1
[property
] = config2
[property
];
73 _cloneConfig: function(config
) {
77 this._copyProperties(clone
, config
);
81 _getAnimationConfigRecursive: function(type
, map
, allConfigs
) {
82 if (!this.animationConfig
) {
89 thisConfig
= this.animationConfig
[type
];
91 thisConfig
= this.animationConfig
;
94 if (!Array
.isArray(thisConfig
)) {
95 thisConfig
= [thisConfig
];
98 // iterate animations and recurse to process configurations from child nodes
100 for (var config
, index
= 0; config
= thisConfig
[index
]; index
++) {
101 if (config
.animatable
) {
102 config
.animatable
._getAnimationConfigRecursive(config
.type
|| type
, map
, allConfigs
);
105 var cachedConfig
= map
[config
.id
];
107 // merge configurations with the same id, making a clone lazily
108 if (!cachedConfig
.isClone
) {
109 map
[config
.id
] = this._cloneConfig(cachedConfig
)
110 cachedConfig
= map
[config
.id
];
112 this._copyProperties(cachedConfig
, config
);
114 // put any configs with an id into a map
115 map
[config
.id
] = config
;
118 allConfigs
.push(config
);
126 * An element implementing `Polymer.NeonAnimationRunnerBehavior` calls this method to configure
127 * an animation with an optional type. Elements implementing `Polymer.NeonAnimatableBehavior`
128 * should define the property `animationConfig`, which is either a configuration object
129 * or a map of animation type to array of configuration objects.
131 getAnimationConfig: function(type
) {
134 this._getAnimationConfigRecursive(type
, map
, allConfigs
);
135 // append the configurations saved in the map to the array
136 for (var key
in map
) {
137 allConfigs
.push(map
[key
]);