| OLD | NEW |
| (Empty) |
| 1 Polymer({ | |
| 2 is: 'app-scrollpos-control', | |
| 3 | |
| 4 properties: { | |
| 5 /** | |
| 6 * The selected page. | |
| 7 */ | |
| 8 selected: { | |
| 9 type: String, | |
| 10 observer: '_selectedChanged' | |
| 11 }, | |
| 12 | |
| 13 /** | |
| 14 * Reset the scroll position to 0. | |
| 15 */ | |
| 16 reset: { | |
| 17 type: Boolean, | |
| 18 value: false | |
| 19 } | |
| 20 }, | |
| 21 | |
| 22 observers: [ | |
| 23 '_updateScrollPos(selected, reset)' | |
| 24 ], | |
| 25 | |
| 26 created: function() { | |
| 27 this._scrollposMap = {}; | |
| 28 }, | |
| 29 | |
| 30 _selectedChanged: function(selected, old) { | |
| 31 if (old != null) { | |
| 32 this._scrollposMap[old] = {x: window.pageXOffset, y: window.pageYOffse
t}; | |
| 33 } | |
| 34 }, | |
| 35 | |
| 36 _updateScrollPos: function(selected, reset) { | |
| 37 this.debounce('_updateScrollPos', function() { | |
| 38 var pos = this._scrollposMap[this.selected]; | |
| 39 if (pos != null && !this.reset) { | |
| 40 this._scrollTo(pos.x, pos.y); | |
| 41 } else { | |
| 42 this._scrollTo(0, 0); | |
| 43 } | |
| 44 }); | |
| 45 }, | |
| 46 | |
| 47 _scrollTo: function(x, y) { | |
| 48 Polymer.AppLayout.scroll({ | |
| 49 left: x, | |
| 50 top: y, | |
| 51 behavior: 'silent' | |
| 52 }); | |
| 53 } | |
| 54 }); | |
| OLD | NEW |