Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / third_party / polymer / v1_0 / components / neon-animation / neon-animatable-behavior.html
blobfac56f8081b3f27addb8b880dbe93d0e0a496005
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.github.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/CONTRIBUTORS.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/PATENTS.txt
8 -->
10 <link rel="import" href="../polymer/polymer.html">
11 <link rel="import" href="animations/opaque-animation.html">
13 <script>
15 /**
16 * `Polymer.NeonAnimatableBehavior` is implemented by elements containing animations for use with
17 * elements implementing `Polymer.NeonAnimationRunnerBehavior`.
18 * @polymerBehavior
20 Polymer.NeonAnimatableBehavior = {
22 properties: {
24 /**
25 * Animation configuration. See README for more info.
27 animationConfig: {
28 type: Object
31 /**
32 * Convenience property for setting an 'entry' animation. Do not set `animationConfig.entry`
33 * manually if using this. The animated node is set to `this` if using this property.
35 entryAnimation: {
36 observer: '_entryAnimationChanged',
37 type: String
40 /**
41 * Convenience property for setting an 'exit' animation. Do not set `animationConfig.exit`
42 * manually if using this. The animated node is set to `this` if using this property.
44 exitAnimation: {
45 observer: '_exitAnimationChanged',
46 type: String
51 _entryAnimationChanged: function() {
52 this.animationConfig = this.animationConfig || {};
53 if (this.entryAnimation !== 'fade-in-animation') {
54 // insert polyfill hack
55 this.animationConfig['entry'] = [{
56 name: 'opaque-animation',
57 node: this
58 }, {
59 name: this.entryAnimation,
60 node: this
61 }];
62 } else {
63 this.animationConfig['entry'] = [{
64 name: this.entryAnimation,
65 node: this
66 }];
70 _exitAnimationChanged: function() {
71 this.animationConfig = this.animationConfig || {};
72 this.animationConfig['exit'] = [{
73 name: this.exitAnimation,
74 node: this
75 }];
78 _copyProperties: function(config1, config2) {
79 // shallowly copy properties from config2 to config1
80 for (var property in config2) {
81 config1[property] = config2[property];
85 _cloneConfig: function(config) {
86 var clone = {
87 isClone: true
89 this._copyProperties(clone, config);
90 return clone;
93 _getAnimationConfigRecursive: function(type, map, allConfigs) {
94 if (!this.animationConfig) {
95 return;
98 // type is optional
99 var thisConfig;
100 if (type) {
101 thisConfig = this.animationConfig[type];
102 } else {
103 thisConfig = this.animationConfig;
106 if (!Array.isArray(thisConfig)) {
107 thisConfig = [thisConfig];
110 // iterate animations and recurse to process configurations from child nodes
111 if (thisConfig) {
112 for (var config, index = 0; config = thisConfig[index]; index++) {
113 if (config.animatable) {
114 config.animatable._getAnimationConfigRecursive(config.type || type, map, allConfigs);
115 } else {
116 if (config.id) {
117 var cachedConfig = map[config.id];
118 if (cachedConfig) {
119 // merge configurations with the same id, making a clone lazily
120 if (!cachedConfig.isClone) {
121 map[config.id] = this._cloneConfig(cachedConfig)
122 cachedConfig = map[config.id];
124 this._copyProperties(cachedConfig, config);
125 } else {
126 // put any configs with an id into a map
127 map[config.id] = config;
129 } else {
130 allConfigs.push(config);
138 * An element implementing `Polymer.NeonAnimationRunnerBehavior` calls this method to configure
139 * an animation with an optional type. Elements implementing `Polymer.NeonAnimatableBehavior`
140 * should define the property `animationConfig`, which is either a configuration object
141 * or a map of animation type to array of configuration objects.
143 getAnimationConfig: function(type) {
144 var map = [];
145 var allConfigs = [];
146 this._getAnimationConfigRecursive(type, map, allConfigs);
147 // append the configurations saved in the map to the array
148 for (var key in map) {
149 allConfigs.push(map[key]);
151 return allConfigs;
156 </script>