OLD | NEW |
(Empty) | |
| 1 <link rel="import" href="../polymer/polymer.html"> |
| 2 <link rel="import" href="polymer-animation.html"> |
| 3 |
| 4 <polymer-element name="polymer-animation-group" extends="polymer-animation" attr
ibutes="type"> |
| 5 <script> |
| 6 (function() { |
| 7 var ANIMATION_GROUPS = { |
| 8 'par': ParGroup, |
| 9 'seq': SeqGroup |
| 10 }; |
| 11 /** |
| 12 * @module Animation |
| 13 */ |
| 14 /** |
| 15 * Component for a group of animations. |
| 16 * |
| 17 * @class polymer-animation-group |
| 18 */ |
| 19 Polymer('polymer-animation-group', { |
| 20 /** |
| 21 * If specified the target will be assigned to all child animations. |
| 22 * @property target |
| 23 * @type HTMLElement|Node |
| 24 * @default null |
| 25 */ |
| 26 targetSelector: '', |
| 27 /** |
| 28 * If specified and not "auto" the duration will apply to the group |
| 29 * and propagate to any child animations that is not a group and does |
| 30 * not specify a duration. |
| 31 * @property duration |
| 32 * @type number |
| 33 * @default "auto" |
| 34 */ |
| 35 duration: 'auto', |
| 36 /** |
| 37 * Group type. 'par' for parallel and 'seq' for sequence. |
| 38 * @property type |
| 39 * @type String |
| 40 * @default 'par' |
| 41 */ |
| 42 type: 'par', |
| 43 typeChanged: function() { |
| 44 this.apply(); |
| 45 }, |
| 46 targetChanged: function() { |
| 47 // Only propagate target to children animations if it's defined. |
| 48 if (this.target) { |
| 49 this.doOnChildren(function(c) { |
| 50 c.target = this.target; |
| 51 }.bind(this)); |
| 52 } |
| 53 }, |
| 54 durationChanged: function() { |
| 55 if (this.duration && this.duration !== 'auto') { |
| 56 this.doOnChildren(function(c) { |
| 57 // Propagate to children that is not a group and has no |
| 58 // duration specified. |
| 59 if (!c.type && (!c.duration || c.duration === 'auto')) { |
| 60 c.duration = this.duration; |
| 61 } |
| 62 }.bind(this)); |
| 63 } |
| 64 }, |
| 65 doOnChildren: function(inFn) { |
| 66 var children = this.children; |
| 67 if (!children.length) { |
| 68 children = this.webkitShadowRoot ? this.webkitShadowRoot.childNodes
: []; |
| 69 } |
| 70 Array.prototype.forEach.call(children, function(c) { |
| 71 // TODO <template> in the way |
| 72 c.apply && inFn(c); |
| 73 }, this); |
| 74 }, |
| 75 makeAnimation: function() { |
| 76 return new ANIMATION_GROUPS[this.type](this.childAnimations, this.timi
ngProps); |
| 77 }, |
| 78 hasTarget: function() { |
| 79 var ht = this.target !== null; |
| 80 if (!ht) { |
| 81 this.doOnChildren(function(c) { |
| 82 ht = ht || c.hasTarget(); |
| 83 }.bind(this)); |
| 84 } |
| 85 return ht; |
| 86 }, |
| 87 apply: function() { |
| 88 // Propagate target and duration to child animations first. |
| 89 this.durationChanged(); |
| 90 this.targetChanged(); |
| 91 this.doOnChildren(function(c) { |
| 92 c.apply(); |
| 93 }); |
| 94 return this.super(); |
| 95 }, |
| 96 get childAnimationElements() { |
| 97 var list = []; |
| 98 this.doOnChildren(function(c) { |
| 99 if (c.makeAnimation) { |
| 100 list.push(c); |
| 101 } |
| 102 }); |
| 103 return list; |
| 104 }, |
| 105 get childAnimations() { |
| 106 var list = []; |
| 107 this.doOnChildren(function(c) { |
| 108 if (c.animation) { |
| 109 list.push(c.animation); |
| 110 } |
| 111 }); |
| 112 return list; |
| 113 } |
| 114 }); |
| 115 })(); |
| 116 </script> |
| 117 </polymer-element> |
OLD | NEW |