Chromium Code Reviews| 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', |
| 11 | 11 |
| 12 properties: { | 12 properties: { |
| 13 /** | 13 /** |
| 14 * Preferences state. | 14 * Preferences state. |
| 15 */ | 15 */ |
| 16 prefs: { | 16 prefs: { |
| 17 type: Object, | 17 type: Object, |
| 18 notify: true, | 18 notify: true, |
| 19 }, | 19 }, |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * The current active route. | 22 * The current active route. |
| 23 * @type {!SettingsRoute} | 23 * @type {!settings.Route} |
| 24 */ | 24 */ |
| 25 currentRoute: { | 25 currentRoute: { |
| 26 type: Object, | 26 type: Object, |
| 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, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 created: function() { | 66 created: function() { |
| 67 /** @private {!PromiseResolver} */ | 67 /** @private {!PromiseResolver} */ |
| 68 this.resolver_ = new PromiseResolver; | 68 this.resolver_ = new PromiseResolver; |
| 69 settings.main.rendered = this.resolver_.promise; | 69 settings.main.rendered = this.resolver_.promise; |
| 70 }, | 70 }, |
| 71 | 71 |
| 72 /** @override */ | 72 /** @override */ |
| 73 attached: function() { | 73 attached: function() { |
| 74 document.addEventListener('toggle-advanced-page', function(e) { | 74 document.addEventListener('toggle-advanced-page', function(e) { |
| 75 this.advancedToggleExpanded_ = e.detail; | 75 this.advancedToggleExpanded_ = e.detail; |
| 76 this.currentRoute = { | 76 settings.navigateTo(this.advancedToggleExpanded_ ? |
| 77 page: this.advancedToggleExpanded_ ? 'advanced' : 'basic', | 77 settings.Route.ADVANCED : settings.Route.BASIC); |
| 78 section: '', | |
| 79 subpage: [], | |
| 80 }; | |
| 81 }.bind(this)); | 78 }.bind(this)); |
| 82 | 79 |
| 83 doWhenReady( | 80 doWhenReady( |
| 84 function() { | 81 function() { |
| 85 var basicPage = this.$$('settings-basic-page'); | 82 var basicPage = this.$$('settings-basic-page'); |
| 86 return !!basicPage && basicPage.scrollHeight > 0; | 83 return !!basicPage && basicPage.scrollHeight > 0; |
| 87 }.bind(this), | 84 }.bind(this), |
| 88 function() { | 85 function() { |
| 89 this.resolver_.resolve(); | 86 this.resolver_.resolve(); |
| 90 }.bind(this)); | 87 }.bind(this)); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 102 /** | 99 /** |
| 103 * @param {boolean} showBasicPage | 100 * @param {boolean} showBasicPage |
| 104 * @param {boolean} inSubpage | 101 * @param {boolean} inSubpage |
| 105 * @return {boolean} | 102 * @return {boolean} |
| 106 */ | 103 */ |
| 107 showAdvancedToggle_: function(showBasicPage, inSubpage) { | 104 showAdvancedToggle_: function(showBasicPage, inSubpage) { |
| 108 return showBasicPage && !inSubpage; | 105 return showBasicPage && !inSubpage; |
| 109 }, | 106 }, |
| 110 | 107 |
| 111 /** | 108 /** |
| 112 * @param {!SettingsRoute} newRoute | |
| 113 * @private | 109 * @private |
| 114 */ | 110 */ |
| 115 currentRouteChanged_: function(newRoute) { | 111 currentRouteChanged_: function(newRoute) { |
| 116 this.inSubpage_ = newRoute.subpage.length > 0; | 112 this.inSubpage_ = newRoute.subpage.length > 0; |
| 117 this.style.height = this.inSubpage_ ? '100%' : ''; | 113 this.style.height = this.inSubpage_ ? '100%' : ''; |
| 118 | 114 |
| 119 if (newRoute.page == 'about') { | 115 if (newRoute.page == 'about') { |
| 120 this.showPages_ = {about: true, basic: false, advanced: false}; | 116 this.showPages_ = {about: true, basic: false, advanced: false}; |
| 121 } else { | 117 } else { |
| 122 this.showPages_ = { | 118 this.showPages_ = { |
| 123 about: false, | 119 about: false, |
| 124 basic: newRoute.page == 'basic' || !this.inSubpage_, | 120 basic: newRoute.page == 'basic' || !this.inSubpage_, |
| 125 advanced: newRoute.page == 'advanced' || | 121 advanced: newRoute.page == 'advanced' || |
| 126 (!this.inSubpage_ && this.advancedToggleExpanded_), | 122 (!this.inSubpage_ && this.advancedToggleExpanded_), |
| 127 }; | 123 }; |
| 128 | 124 |
| 129 if (this.showPages_.advanced) | 125 if (this.showPages_.advanced) |
| 130 this.advancedToggleExpanded_ = true; | 126 this.advancedToggleExpanded_ = true; |
| 131 } | 127 } |
| 132 | 128 |
| 133 // Wait for the dom-if changes prior to calculating the overflow padding. | 129 // Wait for the dom-if changes prior to calculating the overflow padding. |
| 134 this.async(function() { | 130 setTimeout(function() { |
| 135 this.$.overscroll.style.paddingBottom = this.overscrollHeight_() + 'px'; | 131 this.$.overscroll.style.paddingBottom = this.overscrollHeight_() + 'px'; |
| 136 }); | 132 }); |
|
michaelpg
2016/07/27 03:11:35
.bind(this)
| |
| 137 }, | 133 }, |
| 138 | 134 |
| 139 /** | 135 /** |
| 140 * Return the height that the over scroll padding should be set to. | 136 * Return the height that the over scroll padding should be set to. |
| 141 * This is used to determine how much padding to apply to the end of the | 137 * This is used to determine how much padding to apply to the end of the |
| 142 * content so that the last element may align with the top of the content | 138 * content so that the last element may align with the top of the content |
| 143 * area. | 139 * area. |
| 144 * @return {number} | 140 * @return {number} |
| 145 * @private | 141 * @private |
| 146 */ | 142 */ |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 /** @private */ | 179 /** @private */ |
| 184 toggleAdvancedPage_: function() { | 180 toggleAdvancedPage_: function() { |
| 185 this.fire('toggle-advanced-page', !this.advancedToggleExpanded_); | 181 this.fire('toggle-advanced-page', !this.advancedToggleExpanded_); |
| 186 }, | 182 }, |
| 187 | 183 |
| 188 /** | 184 /** |
| 189 * Navigates to the default search page (if necessary). | 185 * Navigates to the default search page (if necessary). |
| 190 * @private | 186 * @private |
| 191 */ | 187 */ |
| 192 ensureInDefaultSearchPage_: function() { | 188 ensureInDefaultSearchPage_: function() { |
| 193 if (this.currentRoute.page != 'basic' || | 189 settings.navigateTo(settings.Route.BASIC); |
| 194 this.currentRoute.section != '' || | |
| 195 this.currentRoute.subpage.length != 0) { | |
| 196 this.currentRoute = {page: 'basic', section: '', subpage: [], url: ''}; | |
| 197 } | |
| 198 }, | 190 }, |
| 199 | 191 |
| 200 /** | 192 /** |
| 201 * @param {string} query | 193 * @param {string} query |
| 202 */ | 194 */ |
| 203 searchContents: function(query) { | 195 searchContents: function(query) { |
| 204 this.ensureInDefaultSearchPage_(); | 196 this.ensureInDefaultSearchPage_(); |
| 205 this.toolbarSpinnerActive = true; | 197 this.toolbarSpinnerActive = true; |
| 206 | 198 |
| 207 // Trigger rendering of the basic and advanced pages and search once ready. | 199 // Trigger rendering of the basic and advanced pages and search once ready. |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 222 return; | 214 return; |
| 223 } | 215 } |
| 224 | 216 |
| 225 this.toolbarSpinnerActive = false; | 217 this.toolbarSpinnerActive = false; |
| 226 this.showNoResultsFound_ = | 218 this.showNoResultsFound_ = |
| 227 !request.isSame('') && !request.didFindMatches(); | 219 !request.isSame('') && !request.didFindMatches(); |
| 228 }.bind(this)); | 220 }.bind(this)); |
| 229 }.bind(this), 0); | 221 }.bind(this), 0); |
| 230 }, | 222 }, |
| 231 }); | 223 }); |
| OLD | NEW |