OLD | NEW |
(Empty) | |
| 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.g
ithub.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/CONTRI
BUTORS.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/PATEN
TS.txt |
| 8 --> |
| 9 <link rel="import" href="../polymer/polymer.html"> |
| 10 <link rel="import" href="../iron-resizable-behavior/iron-resizable-behavior.html
"> |
| 11 <link rel="import" href="../iron-selector/iron-selectable.html"> |
| 12 <link rel="import" href="../paper-styles/paper-styles.html"> |
| 13 <link rel="import" href="neon-animation-runner-behavior.html"> |
| 14 <link rel="import" href="animations/opaque-animation.html"> |
| 15 |
| 16 <!-- |
| 17 `neon-animated-pages` manages a set of pages and runs an animation when switchin
g between them. Its |
| 18 children pages should implement `Polymer.NeonAnimatableBehavior` and define `ent
ry` and `exit` |
| 19 animations to be run when switching to or switching out of the page. |
| 20 |
| 21 @group Neon Elements |
| 22 @element neon-animated-pages |
| 23 @demo demo/index.html |
| 24 --> |
| 25 |
| 26 <dom-module id="neon-animated-pages"> |
| 27 |
| 28 <style> |
| 29 |
| 30 :host { |
| 31 display: block; |
| 32 position: relative; |
| 33 } |
| 34 |
| 35 :host > ::content > * { |
| 36 @apply(--layout-fit); |
| 37 height: 100%; |
| 38 } |
| 39 |
| 40 :host > ::content > :not(.iron-selected):not(.neon-animating) { |
| 41 display: none !important; |
| 42 } |
| 43 |
| 44 :host > ::content > .neon-animating { |
| 45 pointer-events: none; |
| 46 } |
| 47 |
| 48 </style> |
| 49 |
| 50 <template> |
| 51 <content id="content"></content> |
| 52 </template> |
| 53 |
| 54 </dom-module> |
| 55 |
| 56 <script> |
| 57 (function() { |
| 58 |
| 59 Polymer({ |
| 60 |
| 61 is: 'neon-animated-pages', |
| 62 |
| 63 behaviors: [ |
| 64 Polymer.IronResizableBehavior, |
| 65 Polymer.IronSelectableBehavior, |
| 66 Polymer.NeonAnimationRunnerBehavior |
| 67 ], |
| 68 |
| 69 properties: { |
| 70 |
| 71 activateEvent: { |
| 72 type: String, |
| 73 value: '' |
| 74 }, |
| 75 |
| 76 // if true, the initial page selection will also be animated according to
its animation config. |
| 77 animateInitialSelection: { |
| 78 type: Boolean, |
| 79 value: false |
| 80 } |
| 81 |
| 82 }, |
| 83 |
| 84 observers: [ |
| 85 '_selectedChanged(selected)' |
| 86 ], |
| 87 |
| 88 listeners: { |
| 89 'neon-animation-finish': '_onNeonAnimationFinish' |
| 90 }, |
| 91 |
| 92 _selectedChanged: function(selected) { |
| 93 |
| 94 var selectedPage = this.selectedItem; |
| 95 var oldPage = this._prevSelected || false; |
| 96 this._prevSelected = selectedPage; |
| 97 |
| 98 // on initial load and if animateInitialSelection is negated, simply displ
ay selectedPage. |
| 99 if (!oldPage && !this.animateInitialSelection) { |
| 100 this._completeSelectedChanged(); |
| 101 return; |
| 102 } |
| 103 |
| 104 // insert safari fix. |
| 105 this.animationConfig = [{ |
| 106 name: 'opaque-animation', |
| 107 node: selectedPage |
| 108 }]; |
| 109 |
| 110 // configure selectedPage animations. |
| 111 if (this.entryAnimation) { |
| 112 this.animationConfig.push({ |
| 113 name: this.entryAnimation, |
| 114 node: selectedPage |
| 115 }); |
| 116 } else { |
| 117 if (selectedPage.getAnimationConfig) { |
| 118 this.animationConfig.push({ |
| 119 animatable: selectedPage, |
| 120 type: 'entry' |
| 121 }); |
| 122 } |
| 123 } |
| 124 |
| 125 // configure oldPage animations iff exists. |
| 126 if (oldPage) { |
| 127 |
| 128 // cancel the currently running animation if one is ongoing. |
| 129 if (oldPage.classList.contains('neon-animating')) { |
| 130 this._squelchNextFinishEvent = true; |
| 131 this.cancelAnimation(); |
| 132 this._completeSelectedChanged(); |
| 133 } |
| 134 |
| 135 // configure the animation. |
| 136 if (this.exitAnimation) { |
| 137 this.animationConfig.push({ |
| 138 name: this.exitAnimation, |
| 139 node: oldPage |
| 140 }); |
| 141 } else { |
| 142 if (oldPage.getAnimationConfig) { |
| 143 this.animationConfig.push({ |
| 144 animatable: oldPage, |
| 145 type: 'exit' |
| 146 }); |
| 147 } |
| 148 } |
| 149 |
| 150 // display the oldPage during the transition. |
| 151 oldPage.classList.add('neon-animating'); |
| 152 } |
| 153 |
| 154 // display the selectedPage during the transition. |
| 155 selectedPage.classList.add('neon-animating'); |
| 156 |
| 157 // actually run the animations. |
| 158 if (this.animationConfig.length > 1) { |
| 159 |
| 160 // on first load, ensure we run animations only after element is attache
d. |
| 161 if (!this.isAttached) { |
| 162 this.async(function () { |
| 163 this.playAnimation(null, { |
| 164 fromPage: null, |
| 165 toPage: selectedPage |
| 166 }); |
| 167 }); |
| 168 |
| 169 } else { |
| 170 this.playAnimation(null, { |
| 171 fromPage: oldPage, |
| 172 toPage: selectedPage |
| 173 }); |
| 174 } |
| 175 |
| 176 } else { |
| 177 this._completeSelectedChanged(oldPage, selectedPage); |
| 178 } |
| 179 }, |
| 180 |
| 181 _completeSelectedChanged: function(oldPage, selectedPage) { |
| 182 if (selectedPage) { |
| 183 selectedPage.classList.remove('neon-animating'); |
| 184 } |
| 185 if (oldPage) { |
| 186 oldPage.classList.remove('neon-animating'); |
| 187 } |
| 188 if (!selectedPage || !oldPage) { |
| 189 var nodes = Polymer.dom(this.$.content).getDistributedNodes(); |
| 190 for (var node, index = 0; node = nodes[index]; index++) { |
| 191 node.classList && node.classList.remove('neon-animating'); |
| 192 } |
| 193 } |
| 194 this.async(this.notifyResize); |
| 195 }, |
| 196 |
| 197 _onNeonAnimationFinish: function(event) { |
| 198 if (this._squelchNextFinishEvent) { |
| 199 this._squelchNextFinishEvent = false; |
| 200 return; |
| 201 } |
| 202 this._completeSelectedChanged(event.detail.fromPage, event.detail.toPage); |
| 203 } |
| 204 |
| 205 }) |
| 206 |
| 207 })(); |
| 208 </script> |
OLD | NEW |