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
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=
"neon-animation-runner-behavior.html">
13 <link rel=
"import" href=
"animations/opaque-animation.html">
16 `neon-animated-pages` manages a set of pages and runs an animation when switching between them. Its
17 children pages should implement `Polymer.NeonAnimatableBehavior` and define `entry` and `exit`
18 animations to be run when switching to or switching out of the page.
21 @element neon-animated-pages
25 <dom-module id=
"neon-animated-pages">
34 :host
> ::content
> * {
43 :host
> ::content
> :not(.iron-selected):not(.neon-animating) {
44 display: none !important;
47 :host
> ::content
> .neon-animating {
54 <content id=
"content"></content>
64 is
: 'neon-animated-pages',
67 Polymer
.IronResizableBehavior
,
68 Polymer
.IronSelectableBehavior
,
69 Polymer
.NeonAnimationRunnerBehavior
79 // if true, the initial page selection will also be animated according to its animation config.
80 animateInitialSelection
: {
88 '_selectedChanged(selected)'
92 'neon-animation-finish': '_onNeonAnimationFinish'
95 _selectedChanged: function(selected
) {
97 var selectedPage
= this.selectedItem
;
98 var oldPage
= this._valueToItem(this._prevSelected
) || false;
99 this._prevSelected
= selected
;
101 // on initial load and if animateInitialSelection is negated, simply display selectedPage.
102 if (!oldPage
&& !this.animateInitialSelection
) {
103 this._completeSelectedChanged();
107 // insert safari fix.
108 this.animationConfig
= [{
109 name
: 'opaque-animation',
113 // configure selectedPage animations.
114 if (this.entryAnimation
) {
115 this.animationConfig
.push({
116 name
: this.entryAnimation
,
120 if (selectedPage
.getAnimationConfig
) {
121 this.animationConfig
.push({
122 animatable
: selectedPage
,
128 // configure oldPage animations iff exists.
131 // cancel the currently running animation if one is ongoing.
132 if (oldPage
.classList
.contains('neon-animating')) {
133 this._squelchNextFinishEvent
= true;
134 this.cancelAnimation();
135 this._completeSelectedChanged();
138 // configure the animation.
139 if (this.exitAnimation
) {
140 this.animationConfig
.push({
141 name
: this.exitAnimation
,
145 if (oldPage
.getAnimationConfig
) {
146 this.animationConfig
.push({
153 // display the oldPage during the transition.
154 oldPage
.classList
.add('neon-animating');
157 // display the selectedPage during the transition.
158 selectedPage
.classList
.add('neon-animating');
160 // actually run the animations.
161 if (this.animationConfig
.length
> 1) {
163 // on first load, ensure we run animations only after element is attached.
164 if (!this.isAttached
) {
165 this.async(function () {
166 this.playAnimation(undefined, {
173 this.playAnimation(undefined, {
180 this._completeSelectedChanged(oldPage
, selectedPage
);
185 * @param {Object=} oldPage
186 * @param {Object=} selectedPage
188 _completeSelectedChanged: function(oldPage
, selectedPage
) {
190 selectedPage
.classList
.remove('neon-animating');
193 oldPage
.classList
.remove('neon-animating');
195 if (!selectedPage
|| !oldPage
) {
196 var nodes
= Polymer
.dom(this.$.content
).getDistributedNodes();
197 for (var node
, index
= 0; node
= nodes
[index
]; index
++) {
198 node
.classList
&& node
.classList
.remove('neon-animating');
201 this.async(this._notifyPageResize
);
204 _onNeonAnimationFinish: function(event
) {
205 if (this._squelchNextFinishEvent
) {
206 this._squelchNextFinishEvent
= false;
209 this._completeSelectedChanged(event
.detail
.fromPage
, event
.detail
.toPage
);
212 _notifyPageResize: function() {
213 var selectedPage
= this.selectedItem
;
214 this.resizerShouldNotify = function(element
) {
215 return element
== selectedPage
;