3 Polymer('core-animated-pages',{
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 transitionsChanged: function() {
42 this._transitions = this.transitions.split(' ');
45 _transitionsChanged: function(old) {
46 if (this._transitionElements) {
47 this._transitionElements.forEach(function(t) {
51 this._transitionElements = [];
52 this._transitions.forEach(function(transitionId) {
53 var t = this.getTransition(transitionId);
55 this._transitionElements.push(t);
61 getTransition: function(transitionId) {
62 return this.tmeta.byId(transitionId);
65 selectionSelect: function(e, detail) {
66 this.updateSelectedItem();
67 // Wait to call applySelection when we run the transition
70 applyTransition: function(src, dst) {
72 this.cancelAsync(this.animating);
73 this.animating = null;
78 if (this.transitioning.indexOf(src) === -1) {
79 this.transitioning.push(src);
81 if (this.transitioning.indexOf(dst) === -1) {
82 this.transitioning.push(dst);
84 // force src, dst to display
85 src.setAttribute('animate', '');
86 dst.setAttribute('animate', '');
91 easing: 'cubic-bezier(0.4, 0, 0.2, 1)'
94 // fire an event so clients have a chance to do something when the
95 // new page becomes visible but before it draws.
96 this.fire('core-animated-pages-transition-prepare');
100 this._transitionElements.forEach(function(transition) {
101 transition.prepare(this, options);
109 this.applySelection(dst, true);
110 this.applySelection(src, false);
113 this._transitionElements.forEach(function(transition) {
114 transition.go(this, options);
117 if (!this._transitionElements.length) {
120 this.animating = this.async(this.complete.bind(this), null, 5000);
124 complete: function() {
125 if (this.animating) {
126 this.cancelAsync(this.animating);
127 this.animating = null;
130 this.transitioning.forEach(function(t) {
131 t.removeAttribute('animate');
133 this.transitioning = [];
135 this._transitionElements.forEach(function(transition) {
136 transition.ensureComplete(this);
139 this.fire('core-animated-pages-transition-end');
142 transitionEnd: function(e) {
143 if (this.transitioning.length) {
144 var completed = true;
145 this._transitionElements.forEach(function(transition) {
146 if (!transition.completed) {
151 this.job('transitionWatch', function() {
158 selectedChanged: function(old) {
159 this.lastSelected = old;
160 this.super(arguments);
163 selectedItemChanged: function(oldItem) {
164 this.super(arguments);
167 this.applySelection(this.selectedItem, true);
171 if (this.hasAttribute('no-transition') || !this._transitionElements || !this._transitionElements.length) {
172 this.applySelection(oldItem, false);
173 this.applySelection(this.selectedItem, true);
177 if (oldItem && this.selectedItem) {
178 // TODO(sorvell): allow bindings to update first?
181 Platform.endOfMicrotask(function() {
182 self.applyTransition(oldItem, self.selectedItem);