~didrocks/+junk/face-detection-15.04

« back to all changes in this revision

Viewing changes to facedetection/www/bower_components/neon-animation/neon-animatable-behavior.html

  • Committer: Didier Roche
  • Date: 2016-05-10 23:09:11 UTC
  • Revision ID: didier.roche@canonical.com-20160510230911-c7xr490zrj3yrzxd
New version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!--
 
2
@license
 
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
 
9
-->
 
10
 
 
11
<link rel="import" href="../polymer/polymer.html">
 
12
<link rel="import" href="animations/opaque-animation.html">
 
13
 
 
14
<script>
 
15
 
 
16
  /**
 
17
   * `Polymer.NeonAnimatableBehavior` is implemented by elements containing animations for use with
 
18
   * elements implementing `Polymer.NeonAnimationRunnerBehavior`.
 
19
   * @polymerBehavior
 
20
   */
 
21
  Polymer.NeonAnimatableBehavior = {
 
22
 
 
23
    properties: {
 
24
 
 
25
      /**
 
26
       * Animation configuration. See README for more info.
 
27
       */
 
28
      animationConfig: {
 
29
        type: Object
 
30
      },
 
31
 
 
32
      /**
 
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.
 
35
       */
 
36
      entryAnimation: {
 
37
        observer: '_entryAnimationChanged',
 
38
        type: String
 
39
      },
 
40
 
 
41
      /**
 
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.
 
44
       */
 
45
      exitAnimation: {
 
46
        observer: '_exitAnimationChanged',
 
47
        type: String
 
48
      }
 
49
 
 
50
    },
 
51
 
 
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',
 
58
          node: this
 
59
        }, {
 
60
          name: this.entryAnimation,
 
61
          node: this
 
62
        }];
 
63
      } else {
 
64
        this.animationConfig['entry'] = [{
 
65
          name: this.entryAnimation,
 
66
          node: this
 
67
        }];
 
68
      }
 
69
    },
 
70
 
 
71
    _exitAnimationChanged: function() {
 
72
      this.animationConfig = this.animationConfig || {};
 
73
      this.animationConfig['exit'] = [{
 
74
        name: this.exitAnimation,
 
75
        node: this
 
76
      }];
 
77
    },
 
78
 
 
79
    _copyProperties: function(config1, config2) {
 
80
      // shallowly copy properties from config2 to config1
 
81
      for (var property in config2) {
 
82
        config1[property] = config2[property];
 
83
      }
 
84
    },
 
85
 
 
86
    _cloneConfig: function(config) {
 
87
      var clone = {
 
88
        isClone: true
 
89
      };
 
90
      this._copyProperties(clone, config);
 
91
      return clone;
 
92
    },
 
93
 
 
94
    _getAnimationConfigRecursive: function(type, map, allConfigs) {
 
95
      if (!this.animationConfig) {
 
96
        return;
 
97
      }
 
98
 
 
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."));
 
101
        return;
 
102
      }
 
103
 
 
104
      // type is optional
 
105
      var thisConfig;
 
106
      if (type) {
 
107
        thisConfig = this.animationConfig[type];
 
108
      } else {
 
109
        thisConfig = this.animationConfig;
 
110
      }
 
111
 
 
112
      if (!Array.isArray(thisConfig)) {
 
113
        thisConfig = [thisConfig];
 
114
      }
 
115
 
 
116
      // iterate animations and recurse to process configurations from child nodes
 
117
      if (thisConfig) {
 
118
        for (var config, index = 0; config = thisConfig[index]; index++) {
 
119
          if (config.animatable) {
 
120
            config.animatable._getAnimationConfigRecursive(config.type || type, map, allConfigs);
 
121
          } else {
 
122
            if (config.id) {
 
123
              var cachedConfig = map[config.id];
 
124
              if (cachedConfig) {
 
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];
 
129
                }
 
130
                this._copyProperties(cachedConfig, config);
 
131
              } else {
 
132
                // put any configs with an id into a map
 
133
                map[config.id] = config;
 
134
              }
 
135
            } else {
 
136
              allConfigs.push(config);
 
137
            }
 
138
          }
 
139
        }
 
140
      }
 
141
    },
 
142
 
 
143
    /**
 
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.
 
148
     */
 
149
    getAnimationConfig: function(type) {
 
150
      var map = {};
 
151
      var allConfigs = [];
 
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]);
 
156
      }
 
157
      return allConfigs;
 
158
    }
 
159
 
 
160
  };
 
161
 
 
162
</script>