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 * @fileoverview | 6 * @fileoverview |
7 * 'settings-main' displays the selected settings page. | 7 * 'settings-main' displays the selected settings page. |
8 */ | 8 */ |
9 Polymer({ | 9 Polymer({ |
10 is: 'settings-main', | 10 is: 'settings-main', |
(...skipping 16 matching lines...) Expand all Loading... |
27 notify: true, | 27 notify: true, |
28 observer: 'currentRouteChanged_', | 28 observer: 'currentRouteChanged_', |
29 }, | 29 }, |
30 | 30 |
31 /** @private */ | 31 /** @private */ |
32 advancedToggleExpanded_: { | 32 advancedToggleExpanded_: { |
33 type: Boolean, | 33 type: Boolean, |
34 value: false, | 34 value: false, |
35 }, | 35 }, |
36 | 36 |
37 /** @private */ | 37 /** |
| 38 * True if a section is expanded to show a subpage. Initialized using |
| 39 * currentRoute. Toggles based on expand/collapse events so effects can |
| 40 * be deferred until transitions complete. |
| 41 * @private |
| 42 */ |
38 inSubpage_: Boolean, | 43 inSubpage_: Boolean, |
39 | 44 |
40 /** @private */ | 45 /** @private */ |
41 showAboutPage_: Boolean, | 46 showAboutPage_: Boolean, |
42 | 47 |
43 /** @private */ | 48 /** @private */ |
44 showBasicPage_: Boolean, | 49 showBasicPage_: Boolean, |
45 | 50 |
46 /** @private */ | 51 /** @private */ |
47 showAdvancedPage_: Boolean, | 52 showAdvancedPage_: Boolean, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 }.bind(this)); | 94 }.bind(this)); |
90 | 95 |
91 doWhenReady( | 96 doWhenReady( |
92 function() { | 97 function() { |
93 var basicPage = this.$$('settings-basic-page'); | 98 var basicPage = this.$$('settings-basic-page'); |
94 return !!basicPage && basicPage.scrollHeight > 0; | 99 return !!basicPage && basicPage.scrollHeight > 0; |
95 }.bind(this), | 100 }.bind(this), |
96 function() { | 101 function() { |
97 this.resolver_.resolve(); | 102 this.resolver_.resolve(); |
98 }.bind(this)); | 103 }.bind(this)); |
| 104 |
| 105 this.inSubpage_ = this.currentRoute.subpage.length > 0; |
99 }, | 106 }, |
100 | 107 |
101 /** | 108 /** |
102 * @param {boolean} opened Whether the menu is expanded. | 109 * @param {boolean} opened Whether the menu is expanded. |
103 * @return {string} Which icon to use. | 110 * @return {string} Which icon to use. |
104 * @private | 111 * @private |
105 */ | 112 */ |
106 arrowState_: function(opened) { | 113 arrowState_: function(opened) { |
107 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; | 114 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; |
108 }, | 115 }, |
109 | 116 |
110 /** | 117 /** |
111 * @param {!SettingsRoute} newRoute | 118 * @param {!SettingsRoute} newRoute |
112 * @private | 119 * @private |
113 */ | 120 */ |
114 currentRouteChanged_: function(newRoute) { | 121 currentRouteChanged_: function(newRoute) { |
115 this.inSubpage_ = newRoute.subpage.length > 0; | 122 this.updatePagesShown_(); |
116 this.showAboutPage_ = newRoute.page == 'about'; | 123 }, |
| 124 |
| 125 /** @private */ |
| 126 subpageExpanded_: function() { |
| 127 this.inSubpage_ = true; |
| 128 // Hide pages other than the current section's parent page. |
| 129 this.updatePagesShown_(); |
| 130 }, |
| 131 |
| 132 /** @private */ |
| 133 subpageCollapsing_: function() { |
| 134 this.inSubpage_ = false; |
| 135 // Unhide pages before collapsing the full-height section. |
| 136 this.updatePagesShown_(); |
| 137 }, |
| 138 |
| 139 /** |
| 140 * Updates the hidden state of the about, basic and advanced pages, based on |
| 141 * the current route and the Advanced toggle state. |
| 142 * @private |
| 143 */ |
| 144 updatePagesShown_: function() { |
| 145 this.showAboutPage_ = this.currentRoute.page == 'about'; |
117 if (this.showAboutPage_) { | 146 if (this.showAboutPage_) { |
118 this.showBasicPage_ = this.showAdvancedPage_ = false; | 147 this.showBasicPage_ = this.showAdvancedPage_ = false; |
119 } else if (newRoute.page == 'basic') { | 148 } else if (this.currentRoute.page == 'basic') { |
120 this.showBasicPage_ = true; | 149 this.showBasicPage_ = true; |
121 this.showAdvancedPage_ = !this.inSubpage_ && this.advancedToggleExpanded_; | 150 this.showAdvancedPage_ = !this.inSubpage_ && this.advancedToggleExpanded_; |
122 } else if (newRoute.page == 'advanced') { | 151 } else if (this.currentRoute.page == 'advanced') { |
123 this.showBasicPage_ = !this.inSubpage_; | 152 this.showBasicPage_ = !this.inSubpage_; |
124 this.showAdvancedPage_ = this.advancedToggleExpanded_ = true; | 153 this.showAdvancedPage_ = this.advancedToggleExpanded_ = true; |
125 } else { | 154 } else { |
126 assertNotReached('Invalid page ' + newRoute.page); | 155 assertNotReached('Invalid page ' + this.currentRoute.page); |
127 } | 156 } |
128 | |
129 this.style.height = this.inSubpage_ ? '100%' : ''; | |
130 }, | 157 }, |
131 | 158 |
132 /** @private */ | 159 /** @private */ |
133 toggleAdvancedPage_: function() { | 160 toggleAdvancedPage_: function() { |
134 this.fire('toggle-advanced-page', !this.advancedToggleExpanded_); | 161 this.fire('toggle-advanced-page', !this.advancedToggleExpanded_); |
135 }, | 162 }, |
136 | 163 |
137 /** | 164 /** |
138 * Navigates to the default search page (if necessary). | 165 * Navigates to the default search page (if necessary). |
139 * @private | 166 * @private |
(...skipping 21 matching lines...) Expand all Loading... |
161 query, assert(this.$$('settings-basic-page'))); | 188 query, assert(this.$$('settings-basic-page'))); |
162 }.bind(this), 0); | 189 }.bind(this), 0); |
163 | 190 |
164 this.showAdvancedPage_ = true; | 191 this.showAdvancedPage_ = true; |
165 setTimeout(function() { | 192 setTimeout(function() { |
166 settings.getSearchManager().search( | 193 settings.getSearchManager().search( |
167 query, assert(this.$$('settings-advanced-page'))); | 194 query, assert(this.$$('settings-advanced-page'))); |
168 }.bind(this), 0); | 195 }.bind(this), 0); |
169 }, | 196 }, |
170 }); | 197 }); |
OLD | NEW |