| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * Responds to route changes by expanding, collapsing, or scrolling to sections | 6 * Responds to route changes by expanding, collapsing, or scrolling to sections |
| 7 * on the page. Expanded sections take up the full height of the container. At | 7 * on the page. Expanded sections take up the full height of the container. At |
| 8 * most one section should be expanded at any given time. | 8 * most one section should be expanded at any given time. |
| 9 * @polymerBehavior MainPageBehavior | 9 * @polymerBehavior MainPageBehavior |
| 10 */ | 10 */ |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 return; | 94 return; |
| 95 } | 95 } |
| 96 | 96 |
| 97 var promise; | 97 var promise; |
| 98 var expandedSection = /** @type {?SettingsSectionElement} */( | 98 var expandedSection = /** @type {?SettingsSectionElement} */( |
| 99 this.$$('settings-section.expanded')); | 99 this.$$('settings-section.expanded')); |
| 100 if (expandedSection) { | 100 if (expandedSection) { |
| 101 // If the section shouldn't be expanded, collapse it. | 101 // If the section shouldn't be expanded, collapse it. |
| 102 if (!currentRoute.isSubpage() || expandedSection != currentSection) { | 102 if (!currentRoute.isSubpage() || expandedSection != currentSection) { |
| 103 promise = this.collapseSection_(expandedSection); | 103 promise = this.collapseSection_(expandedSection); |
| 104 // Scroll to the collapsed section. | |
| 105 if (currentSection && scrollToSection) | |
| 106 currentSection.scrollIntoView(); | |
| 107 } else { | 104 } else { |
| 108 // Scroll to top while sliding to another subpage. | 105 // Scroll to top while sliding to another subpage. |
| 109 this.scroller.scrollTop = 0; | 106 this.scroller.scrollTop = 0; |
| 110 } | 107 } |
| 111 } else if (currentSection) { | 108 } else if (currentSection) { |
| 112 // Expand the section into a subpage or scroll to it on the main page. | 109 // Expand the section into a subpage or scroll to it on the main page. |
| 113 if (currentRoute.isSubpage()) | 110 if (currentRoute.isSubpage()) |
| 114 promise = this.expandSection_(currentSection); | 111 promise = this.expandSection_(currentSection); |
| 115 else if (scrollToSection) | 112 else if (scrollToSection) |
| 116 currentSection.scrollIntoView(); | 113 currentSection.scrollIntoView(); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 return Promise.resolve(); | 243 return Promise.resolve(); |
| 247 } | 244 } |
| 248 | 245 |
| 249 // Play the actual collapse animation. | 246 // Play the actual collapse animation. |
| 250 return new Promise(function(resolve, reject) { | 247 return new Promise(function(resolve, reject) { |
| 251 // Wait for the other sections to show up so we can scroll properly. | 248 // Wait for the other sections to show up so we can scroll properly. |
| 252 setTimeout(function() { | 249 setTimeout(function() { |
| 253 var newSection = settings.getCurrentRoute().section && | 250 var newSection = settings.getCurrentRoute().section && |
| 254 this.getSection(settings.getCurrentRoute().section); | 251 this.getSection(settings.getCurrentRoute().section); |
| 255 | 252 |
| 256 this.scroller.scrollTop = this.origScrollTop_; | 253 // Scroll to the new section or the original position. |
| 254 if (newSection && !settings.lastRouteChangeWasPopstate()) |
| 255 newSection.scrollIntoView(); |
| 256 else |
| 257 this.scroller.scrollTop = this.origScrollTop_; |
| 257 | 258 |
| 258 this.currentAnimation_ = section.animateCollapse( | 259 this.currentAnimation_ = section.animateCollapse( |
| 259 /** @type {!HTMLElement} */(this.scroller)); | 260 /** @type {!HTMLElement} */(this.scroller)); |
| 260 | 261 |
| 261 this.currentAnimation_.finished.catch(function() { | 262 this.currentAnimation_.finished.catch(function() { |
| 262 // The collapse was canceled, so the page is showing a subpage still. | 263 // The collapse was canceled, so the page is showing a subpage still. |
| 263 this.fire('subpage-expand'); | 264 this.fire('subpage-expand'); |
| 264 }.bind(this)).then(function() { | 265 }.bind(this)).then(function() { |
| 265 // Clean up after the animation succeeds or cancels. | 266 // Clean up after the animation succeeds or cancels. |
| 266 section.setFrozen(false); | 267 section.setFrozen(false); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 return /** @type {?SettingsSectionElement} */( | 299 return /** @type {?SettingsSectionElement} */( |
| 299 this.$$('settings-section[section="' + section + '"]')); | 300 this.$$('settings-section[section="' + section + '"]')); |
| 300 }, | 301 }, |
| 301 }; | 302 }; |
| 302 | 303 |
| 303 /** @polymerBehavior */ | 304 /** @polymerBehavior */ |
| 304 var MainPageBehavior = [ | 305 var MainPageBehavior = [ |
| 305 settings.RouteObserverBehavior, | 306 settings.RouteObserverBehavior, |
| 306 MainPageBehaviorImpl, | 307 MainPageBehaviorImpl, |
| 307 ]; | 308 ]; |
| OLD | NEW |