2 * `Polymer.NeonAnimatableBehavior` is implemented by elements containing animations for use with
3 * elements implementing `Polymer.NeonAnimationRunnerBehavior`.
6 Polymer
.NeonAnimatableBehavior
= {
11 * Animation configuration. See README for more info.
18 * Convenience property for setting an 'entry' animation. Do not set `animationConfig.entry`
19 * manually if using this. The animated node is set to `this` if using this property.
22 observer
: '_entryAnimationChanged',
27 * Convenience property for setting an 'exit' animation. Do not set `animationConfig.exit`
28 * manually if using this. The animated node is set to `this` if using this property.
31 observer
: '_exitAnimationChanged',
37 _entryAnimationChanged: function() {
38 this.animationConfig
= this.animationConfig
|| {};
39 if (this.entryAnimation
!== 'fade-in-animation') {
40 // insert polyfill hack
41 this.animationConfig
['entry'] = [{
42 name
: 'opaque-animation',
45 name
: this.entryAnimation
,
49 this.animationConfig
['entry'] = [{
50 name
: this.entryAnimation
,
56 _exitAnimationChanged: function() {
57 this.animationConfig
= this.animationConfig
|| {};
58 this.animationConfig
['exit'] = [{
59 name
: this.exitAnimation
,
64 _copyProperties: function(config1
, config2
) {
65 // shallowly copy properties from config2 to config1
66 for (var property
in config2
) {
67 config1
[property
] = config2
[property
];
71 _cloneConfig: function(config
) {
75 this._copyProperties(clone
, config
);
79 _getAnimationConfigRecursive: function(type
, map
, allConfigs
) {
80 if (!this.animationConfig
) {
87 thisConfig
= this.animationConfig
[type
];
89 thisConfig
= this.animationConfig
;
92 if (!Array
.isArray(thisConfig
)) {
93 thisConfig
= [thisConfig
];
96 // iterate animations and recurse to process configurations from child nodes
98 for (var config
, index
= 0; config
= thisConfig
[index
]; index
++) {
99 if (config
.animatable
) {
100 config
.animatable
._getAnimationConfigRecursive(config
.type
|| type
, map
, allConfigs
);
103 var cachedConfig
= map
[config
.id
];
105 // merge configurations with the same id, making a clone lazily
106 if (!cachedConfig
.isClone
) {
107 map
[config
.id
] = this._cloneConfig(cachedConfig
)
108 cachedConfig
= map
[config
.id
];
110 this._copyProperties(cachedConfig
, config
);
112 // put any configs with an id into a map
113 map
[config
.id
] = config
;
116 allConfigs
.push(config
);
124 * An element implementing `Polymer.NeonAnimationRunnerBehavior` calls this method to configure
125 * an animation with an optional type. Elements implementing `Polymer.NeonAnimatableBehavior`
126 * should define the property `animationConfig`, which is either a configuration object
127 * or a map of animation type to array of configuration objects.
129 getAnimationConfig: function(type
) {
132 this._getAnimationConfigRecursive(type
, map
, allConfigs
);
133 // append the configurations saved in the map to the array
134 for (var key
in map
) {
135 allConfigs
.push(map
[key
]);