| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 * @typedef {{about: boolean, basic: boolean, advanced: boolean}} | 6 * @typedef {{about: boolean, basic: boolean, advanced: boolean}} |
| 7 */ | 7 */ |
| 8 var MainPageVisibility; | 8 var MainPageVisibility; |
| 9 | 9 |
| 10 /** | 10 /** |
| 11 * @fileoverview | 11 * @fileoverview |
| 12 * 'settings-main' displays the selected settings page. | 12 * 'settings-main' displays the selected settings page. |
| 13 */ | 13 */ |
| 14 Polymer({ | 14 Polymer({ |
| 15 is: 'settings-main', | 15 is: 'settings-main', |
| 16 | 16 |
| 17 behaviors: [settings.RouteObserverBehavior], | 17 behaviors: [settings.RouteObserverBehavior], |
| 18 | 18 |
| 19 properties: { | 19 properties: { |
| 20 /** | 20 /** |
| 21 * Preferences state. | 21 * Preferences state. |
| 22 */ | 22 */ |
| 23 prefs: { | 23 prefs: { |
| 24 type: Object, | 24 type: Object, |
| 25 notify: true, | 25 notify: true, |
| 26 }, | 26 }, |
| 27 | 27 |
| 28 /** @private */ | 28 advancedToggleExpanded: { |
| 29 advancedToggleExpanded_: { | |
| 30 type: Boolean, | 29 type: Boolean, |
| 31 value: false, | 30 notify: true, |
| 31 observer: 'updatePagesShown_', |
| 32 }, | 32 }, |
| 33 | 33 |
| 34 /** | 34 /** |
| 35 * True if a section is fully expanded to hide other sections beneath it. | 35 * True if a section is fully expanded to hide other sections beneath it. |
| 36 * Not true otherwise (even while animating a section open/closed). | 36 * Not true otherwise (even while animating a section open/closed). |
| 37 * @private | 37 * @private |
| 38 */ | 38 */ |
| 39 hasExpandedSection_: Boolean, | 39 hasExpandedSection_: Boolean, |
| 40 | 40 |
| 41 /** @private */ | 41 /** @private */ |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 * @type {!GuestModePageVisibility} | 83 * @type {!GuestModePageVisibility} |
| 84 */ | 84 */ |
| 85 pageVisibility: { | 85 pageVisibility: { |
| 86 type: Object, | 86 type: Object, |
| 87 value: function() { return {}; }, | 87 value: function() { return {}; }, |
| 88 }, | 88 }, |
| 89 }, | 89 }, |
| 90 | 90 |
| 91 /** @override */ | 91 /** @override */ |
| 92 attached: function() { | 92 attached: function() { |
| 93 document.addEventListener('toggle-advanced-page', function(e) { | |
| 94 this.advancedToggleExpanded_ = e.detail; | |
| 95 this.updatePagesShown_(); | |
| 96 }.bind(this)); | |
| 97 | |
| 98 var currentRoute = settings.getCurrentRoute(); | 93 var currentRoute = settings.getCurrentRoute(); |
| 99 this.hasExpandedSection_ = currentRoute && currentRoute.isSubpage(); | 94 this.hasExpandedSection_ = currentRoute && currentRoute.isSubpage(); |
| 100 }, | 95 }, |
| 101 | 96 |
| 102 /** @private */ | 97 /** @private */ |
| 103 overscrollChanged_: function() { | 98 overscrollChanged_: function() { |
| 104 if (!this.overscroll_ && this.boundScroll_) { | 99 if (!this.overscroll_ && this.boundScroll_) { |
| 105 this.offsetParent.removeEventListener('scroll', this.boundScroll_); | 100 this.offsetParent.removeEventListener('scroll', this.boundScroll_); |
| 106 window.removeEventListener('resize', this.boundScroll_); | 101 window.removeEventListener('resize', this.boundScroll_); |
| 107 this.boundScroll_ = null; | 102 this.boundScroll_ = null; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 }, | 194 }, |
| 200 | 195 |
| 201 /** @param {!settings.Route} newRoute */ | 196 /** @param {!settings.Route} newRoute */ |
| 202 currentRouteChanged: function(newRoute) { | 197 currentRouteChanged: function(newRoute) { |
| 203 // When the route changes from a sub-page to the main page, immediately | 198 // When the route changes from a sub-page to the main page, immediately |
| 204 // update hasExpandedSection_ to unhide the other sections. | 199 // update hasExpandedSection_ to unhide the other sections. |
| 205 if (!newRoute.isSubpage()) | 200 if (!newRoute.isSubpage()) |
| 206 this.hasExpandedSection_ = false; | 201 this.hasExpandedSection_ = false; |
| 207 | 202 |
| 208 if (settings.Route.ADVANCED.contains(newRoute)) | 203 if (settings.Route.ADVANCED.contains(newRoute)) |
| 209 this.advancedToggleExpanded_ = true; | 204 this.advancedToggleExpanded = true; |
| 210 | 205 |
| 211 this.updatePagesShown_(); | 206 this.updatePagesShown_(); |
| 212 }, | 207 }, |
| 213 | 208 |
| 214 /** @private */ | 209 /** @private */ |
| 215 onSubpageExpand_: function() { | 210 onSubpageExpand_: function() { |
| 216 // The subpage finished expanding fully. Hide pages other than the current | 211 // The subpage finished expanding fully. Hide pages other than the current |
| 217 // section's parent page. | 212 // section's parent page. |
| 218 this.hasExpandedSection_ = true; | 213 this.hasExpandedSection_ = true; |
| 219 this.updatePagesShown_(); | 214 this.updatePagesShown_(); |
| 220 }, | 215 }, |
| 221 | 216 |
| 222 /** | 217 /** |
| 223 * Updates the hidden state of the about, basic and advanced pages, based on | 218 * Updates the hidden state of the about, basic and advanced pages, based on |
| 224 * the current route and the Advanced toggle state. | 219 * the current route and the Advanced toggle state. |
| 225 * @private | 220 * @private |
| 226 */ | 221 */ |
| 227 updatePagesShown_: function() { | 222 updatePagesShown_: function() { |
| 228 var currentRoute = settings.getCurrentRoute(); | 223 var currentRoute = settings.getCurrentRoute(); |
| 229 if (settings.Route.ABOUT.contains(currentRoute)) { | 224 if (settings.Route.ABOUT.contains(currentRoute)) { |
| 230 this.showPages_ = {about: true, basic: false, advanced: false}; | 225 this.showPages_ = {about: true, basic: false, advanced: false}; |
| 231 } else { | 226 } else { |
| 232 this.showPages_ = { | 227 this.showPages_ = { |
| 233 about: false, | 228 about: false, |
| 234 basic: settings.Route.BASIC.contains(currentRoute) || | 229 basic: settings.Route.BASIC.contains(currentRoute) || |
| 235 !this.hasExpandedSection_, | 230 !this.hasExpandedSection_, |
| 236 advanced: this.hasExpandedSection_ ? | 231 advanced: this.hasExpandedSection_ ? |
| 237 settings.Route.ADVANCED.contains(currentRoute) : | 232 settings.Route.ADVANCED.contains(currentRoute) : |
| 238 this.advancedToggleExpanded_, | 233 this.advancedToggleExpanded, |
| 239 }; | 234 }; |
| 240 } | 235 } |
| 241 | 236 |
| 242 // Calculate and set the overflow padding. | 237 // Calculate and set the overflow padding. |
| 243 this.updateOverscrollForPage_(); | 238 this.updateOverscrollForPage_(); |
| 244 | 239 |
| 245 // Wait for any other changes, then calculate the overflow padding again. | 240 // Wait for any other changes, then calculate the overflow padding again. |
| 246 setTimeout(function() { | 241 setTimeout(function() { |
| 247 // Ensure any dom-if reflects the current properties. | 242 // Ensure any dom-if reflects the current properties. |
| 248 Polymer.dom.flush(); | 243 Polymer.dom.flush(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 | 280 |
| 286 // Find the distance from the section's top to the overscroll. | 281 // Find the distance from the section's top to the overscroll. |
| 287 var sectionTop = section.offsetParent.offsetTop + section.offsetTop; | 282 var sectionTop = section.offsetParent.offsetTop + section.offsetTop; |
| 288 var distance = this.$.overscroll.offsetTop - sectionTop; | 283 var distance = this.$.overscroll.offsetTop - sectionTop; |
| 289 | 284 |
| 290 return Math.max(0, this.offsetParent.clientHeight - distance); | 285 return Math.max(0, this.offsetParent.clientHeight - distance); |
| 291 }, | 286 }, |
| 292 | 287 |
| 293 /** @private */ | 288 /** @private */ |
| 294 toggleAdvancedPage_: function() { | 289 toggleAdvancedPage_: function() { |
| 295 this.fire('toggle-advanced-page', !this.advancedToggleExpanded_); | 290 this.advancedToggleExpanded = !this.advancedToggleExpanded; |
| 296 }, | 291 }, |
| 297 | 292 |
| 298 /** | 293 /** |
| 299 * Returns the root page (if it exists) for a route. | 294 * Returns the root page (if it exists) for a route. |
| 300 * @param {!settings.Route} route | 295 * @param {!settings.Route} route |
| 301 * @return {(?SettingsAboutPageElement|?SettingsAdvancedPageElement| | 296 * @return {(?SettingsAboutPageElement|?SettingsAdvancedPageElement| |
| 302 * ?SettingsBasicPageElement)} | 297 * ?SettingsBasicPageElement)} |
| 303 */ | 298 */ |
| 304 getPage_: function(route) { | 299 getPage_: function(route) { |
| 305 if (settings.Route.ABOUT.contains(route)) { | 300 if (settings.Route.ABOUT.contains(route)) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 | 360 |
| 366 /** | 361 /** |
| 367 * @param {(boolean|undefined)} visibility | 362 * @param {(boolean|undefined)} visibility |
| 368 * @return {boolean} True unless visibility is false. | 363 * @return {boolean} True unless visibility is false. |
| 369 * @private | 364 * @private |
| 370 */ | 365 */ |
| 371 showAdvancedSettings_: function(visibility) { | 366 showAdvancedSettings_: function(visibility) { |
| 372 return visibility !== false; | 367 return visibility !== false; |
| 373 }, | 368 }, |
| 374 }); | 369 }); |
| OLD | NEW |