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 /** |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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) { | 93 document.addEventListener('toggle-advanced-page', function(e) { |
94 this.advancedToggleExpanded_ = e.detail; | 94 this.advancedToggleExpanded_ = e.detail; |
95 this.currentRouteChanged(settings.getCurrentRoute()); | 95 this.updatePagesShown_(); |
96 }.bind(this)); | 96 }.bind(this)); |
97 | 97 |
98 var currentRoute = settings.getCurrentRoute(); | 98 var currentRoute = settings.getCurrentRoute(); |
99 this.hasExpandedSection_ = currentRoute && currentRoute.isSubpage(); | 99 this.hasExpandedSection_ = currentRoute && currentRoute.isSubpage(); |
100 }, | 100 }, |
101 | 101 |
102 /** @private */ | 102 /** @private */ |
103 overscrollChanged_: function() { | 103 overscrollChanged_: function() { |
104 if (!this.overscroll_ && this.boundScroll_) { | 104 if (!this.overscroll_ && this.boundScroll_) { |
105 this.offsetParent.removeEventListener('scroll', this.boundScroll_); | 105 this.offsetParent.removeEventListener('scroll', this.boundScroll_); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 var inSearchMode = !!this.previousShowPages_; | 145 var inSearchMode = !!this.previousShowPages_; |
146 return !inSearchMode && this.showPages_.basic && !this.hasExpandedSection_; | 146 return !inSearchMode && this.showPages_.basic && !this.hasExpandedSection_; |
147 }, | 147 }, |
148 | 148 |
149 currentRouteChanged: function(newRoute) { | 149 currentRouteChanged: function(newRoute) { |
150 // When the route changes from a sub-page to the main page, immediately | 150 // When the route changes from a sub-page to the main page, immediately |
151 // update hasExpandedSection_ to unhide the other sections. | 151 // update hasExpandedSection_ to unhide the other sections. |
152 if (!newRoute.isSubpage()) | 152 if (!newRoute.isSubpage()) |
153 this.hasExpandedSection_ = false; | 153 this.hasExpandedSection_ = false; |
154 | 154 |
155 this.advancedToggleExpanded_ = settings.Route.ADVANCED.contains(newRoute); | |
dschuyler
2016/09/01 23:36:00
This looks like it may collapse advanced if the
ur
tommycli
2016/09/02 00:36:21
Done. And added a test
| |
156 | |
155 this.updatePagesShown_(); | 157 this.updatePagesShown_(); |
156 }, | 158 }, |
157 | 159 |
158 /** @private */ | 160 /** @private */ |
159 onSubpageExpand_: function() { | 161 onSubpageExpand_: function() { |
160 // The subpage finished expanding fully. Hide pages other than the current | 162 // The subpage finished expanding fully. Hide pages other than the current |
161 // section's parent page. | 163 // section's parent page. |
162 this.hasExpandedSection_ = true; | 164 this.hasExpandedSection_ = true; |
163 this.updatePagesShown_(); | 165 this.updatePagesShown_(); |
164 }, | 166 }, |
165 | 167 |
166 /** | 168 /** |
167 * Updates the hidden state of the about, basic and advanced pages, based on | 169 * Updates the hidden state of the about, basic and advanced pages, based on |
168 * the current route and the Advanced toggle state. | 170 * the current route and the Advanced toggle state. |
169 * @private | 171 * @private |
170 */ | 172 */ |
171 updatePagesShown_: function() { | 173 updatePagesShown_: function() { |
172 var currentRoute = settings.getCurrentRoute(); | 174 var currentRoute = settings.getCurrentRoute(); |
173 if (settings.Route.ABOUT.contains(currentRoute)) { | 175 if (settings.Route.ABOUT.contains(currentRoute)) { |
174 this.showPages_ = {about: true, basic: false, advanced: false}; | 176 this.showPages_ = {about: true, basic: false, advanced: false}; |
175 } else { | 177 } else { |
176 this.showPages_ = { | 178 this.showPages_ = { |
177 about: false, | 179 about: false, |
178 basic: settings.Route.BASIC.contains(currentRoute) || | 180 basic: settings.Route.BASIC.contains(currentRoute) || |
179 !this.hasExpandedSection_, | 181 !this.hasExpandedSection_, |
180 advanced: settings.Route.ADVANCED.contains(currentRoute) || | 182 advanced: this.advancedToggleExpanded_ || |
181 (!this.hasExpandedSection_ && this.advancedToggleExpanded_), | 183 (settings.Route.ADVANCED.contains(currentRoute) && |
184 this.hasExpandedSection_), | |
182 }; | 185 }; |
183 | |
184 if (this.showPages_.advanced) { | |
185 assert(!this.pageVisibility || | |
186 this.pageVisibility.advancedSettings !== false); | |
187 this.advancedToggleExpanded_ = true; | |
188 } | |
189 } | 186 } |
190 | 187 |
191 // Wait for any other changes prior to calculating the overflow padding. | 188 // Wait for any other changes prior to calculating the overflow padding. |
192 setTimeout(function() { | 189 setTimeout(function() { |
193 // Ensure any dom-if reflects the current properties. | 190 // Ensure any dom-if reflects the current properties. |
194 Polymer.dom.flush(); | 191 Polymer.dom.flush(); |
195 | 192 |
196 this.setOverscroll_(this.overscrollHeight_()); | 193 this.setOverscroll_(this.overscrollHeight_()); |
197 }.bind(this)); | 194 }.bind(this)); |
198 }, | 195 }, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 | 307 |
311 /** | 308 /** |
312 * @param {(boolean|undefined)} visibility | 309 * @param {(boolean|undefined)} visibility |
313 * @return {boolean} True unless visibility is false. | 310 * @return {boolean} True unless visibility is false. |
314 * @private | 311 * @private |
315 */ | 312 */ |
316 showAdvancedSettings_: function(visibility) { | 313 showAdvancedSettings_: function(visibility) { |
317 return visibility !== false; | 314 return visibility !== false; |
318 }, | 315 }, |
319 }); | 316 }); |
OLD | NEW |