3 Polymer('core-animated-pages',Polymer.mixin({
6 'core-transitionend': 'transitionEnd'
10 * A space-delimited string of transitions to use when switching between pages in this element.
11 * The strings are `id`s of `core-transition-pages` elements included elsewhere. See the
12 * individual transition's document for specific details.
14 * @attribute transitions
23 * The last page selected. This property is useful to dynamically set transitions based
24 * on incoming and outgoing pages.
26 * @attribute lastSelected
32 registerCallback: function() {
33 this.tmeta = document.createElement('core-transition');
37 this._transitions = [];
38 this.transitioning = [];
41 attached: function() {
42 this.resizerAttachedHandler();
45 detached: function() {
46 this.resizerDetachedHandler();
49 transitionsChanged: function() {
50 this._transitions = this.transitions.split(' ');
53 _transitionsChanged: function(old) {
54 if (this._transitionElements) {
55 this._transitionElements.forEach(function(t) {
59 this._transitionElements = [];
60 this._transitions.forEach(function(transitionId) {
61 var t = this.getTransition(transitionId);
63 this._transitionElements.push(t);
69 getTransition: function(transitionId) {
70 return this.tmeta.byId(transitionId);
73 selectionSelect: function(e, detail) {
74 this.updateSelectedItem();
75 // Wait to call applySelection when we run the transition
78 applyTransition: function(src, dst) {
80 this.cancelAsync(this.animating);
81 this.animating = null;
86 if (this.transitioning.indexOf(src) === -1) {
87 this.transitioning.push(src);
89 if (this.transitioning.indexOf(dst) === -1) {
90 this.transitioning.push(dst);
92 // force src, dst to display
93 src.setAttribute('animate', '');
94 dst.setAttribute('animate', '');
99 easing: 'cubic-bezier(0.4, 0, 0.2, 1)'
102 // fire an event so clients have a chance to do something when the
103 // new page becomes visible but before it draws.
104 this.fire('core-animated-pages-transition-prepare');
107 // prepare transition
108 this._transitionElements.forEach(function(transition) {
109 transition.prepare(this, options);
117 this.applySelection(dst, true);
118 this.applySelection(src, false);
121 this._transitionElements.forEach(function(transition) {
122 transition.go(this, options);
125 if (!this._transitionElements.length) {
128 this.animating = this.async(this.complete.bind(this), null, 5000);
132 complete: function() {
133 if (this.animating) {
134 this.cancelAsync(this.animating);
135 this.animating = null;
138 this.transitioning.forEach(function(t) {
139 t.removeAttribute('animate');
141 this.transitioning = [];
143 this._transitionElements.forEach(function(transition) {
144 transition.ensureComplete(this);
147 this.fire('core-animated-pages-transition-end');
150 transitionEnd: function(e) {
151 if (this.transitioning.length) {
152 var completed = true;
153 this._transitionElements.forEach(function(transition) {
154 if (!transition.completed) {
159 this.job('transitionWatch', function() {
166 selectedChanged: function(old) {
167 this.lastSelected = old;
168 this.super(arguments);
171 selectedItemChanged: function(oldItem) {
172 this.super(arguments);
175 this.applySelection(this.selectedItem, true);
179 if (this.hasAttribute('no-transition') || !this._transitionElements || !this._transitionElements.length) {
180 this.applySelection(oldItem, false);
181 this.applySelection(this.selectedItem, true);
186 if (oldItem && this.selectedItem) {
187 // TODO(sorvell): allow bindings to update first?
190 Polymer.endOfMicrotask(function() {
191 self.applyTransition(oldItem, self.selectedItem);
197 resizerShouldNotify: function(el) {
198 // Only notify descendents of selected item
199 while (el && (el != this)) {
200 if (el == this.selectedItem) {
203 el = el.parentElement || (el.parentNode && el.parentNode.host);
207 }, Polymer.CoreResizer));