| 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-ui' implements the UI for the Settings page. | 7 * 'settings-ui' implements the UI for the Settings page. |
| 8 * | 8 * |
| 9 * Example: | 9 * Example: |
| 10 * | 10 * |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 115 |
| 116 /** @override */ | 116 /** @override */ |
| 117 attached: function() { | 117 attached: function() { |
| 118 // Preload bold Roboto so it doesn't load and flicker the first time used. | 118 // Preload bold Roboto so it doesn't load and flicker the first time used. |
| 119 document.fonts.load('bold 12px Roboto'); | 119 document.fonts.load('bold 12px Roboto'); |
| 120 settings.setGlobalScrollTarget(this.$.headerPanel.scroller); | 120 settings.setGlobalScrollTarget(this.$.headerPanel.scroller); |
| 121 }, | 121 }, |
| 122 | 122 |
| 123 /** @param {!settings.Route} route */ | 123 /** @param {!settings.Route} route */ |
| 124 currentRouteChanged: function(route) { | 124 currentRouteChanged: function(route) { |
| 125 // New searches always take place on the BASIC route. Navigations into | |
| 126 // subpages are either non-searches, or continuations of an existing search. | |
| 127 // | |
| 128 // TODO(dpapad): Address corner-case where the user: | |
| 129 // 1) Visits a subpage first. | |
| 130 // 2) Triggers a search. | |
| 131 // 3) Clicks the "back" button. | |
| 132 // Currently nothing happens. Should clear search results and navigate to | |
| 133 // the subpage instead. | |
| 134 if (route.isSubpage()) | |
| 135 return; | |
| 136 | |
| 137 var urlSearchQuery = settings.getQueryParameters().get('search') || ''; | 125 var urlSearchQuery = settings.getQueryParameters().get('search') || ''; |
| 138 if (urlSearchQuery == this.lastSearchQuery_) | 126 if (urlSearchQuery == this.lastSearchQuery_) |
| 139 return; | 127 return; |
| 140 | 128 |
| 141 this.lastSearchQuery_ = urlSearchQuery; | 129 this.lastSearchQuery_ = urlSearchQuery; |
| 142 | 130 |
| 143 var toolbar = /** @type {!CrToolbarElement} */ (this.$$('cr-toolbar')); | 131 var toolbar = /** @type {!CrToolbarElement} */ (this.$$('cr-toolbar')); |
| 144 var searchField = /** @type {CrToolbarSearchFieldElement} */ ( | 132 var searchField = /** @type {CrToolbarSearchFieldElement} */ ( |
| 145 toolbar.getSearchField()); | 133 toolbar.getSearchField()); |
| 146 | 134 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 164 // Trim leading whitespace only, to prevent searching for empty string. This | 152 // Trim leading whitespace only, to prevent searching for empty string. This |
| 165 // still allows the user to search for 'foo bar', while taking a long pause | 153 // still allows the user to search for 'foo bar', while taking a long pause |
| 166 // after typing 'foo '. | 154 // after typing 'foo '. |
| 167 var query = e.detail.replace(/^\s+/, ''); | 155 var query = e.detail.replace(/^\s+/, ''); |
| 168 // Prevent duplicate history entries. | 156 // Prevent duplicate history entries. |
| 169 if (query == this.lastSearchQuery_) | 157 if (query == this.lastSearchQuery_) |
| 170 return; | 158 return; |
| 171 | 159 |
| 172 settings.navigateTo( | 160 settings.navigateTo( |
| 173 settings.Route.BASIC, | 161 settings.Route.BASIC, |
| 174 query.length > 0 ? | 162 query.length > 0 ? new URLSearchParams(`search=${query}`) : undefined, |
| 175 new URLSearchParams(`search=${query}`) : undefined); | 163 /* removeSearch */ true); |
| 176 }, | 164 }, |
| 177 | 165 |
| 178 /** | 166 /** |
| 179 * @param {Event} event | 167 * @param {Event} event |
| 180 * @private | 168 * @private |
| 181 */ | 169 */ |
| 182 onIronActivate_: function(event) { | 170 onIronActivate_: function(event) { |
| 183 if (event.detail.item.id != 'advancedPage') | 171 if (event.detail.item.id != 'advancedPage') |
| 184 this.$$('app-drawer').close(); | 172 this.$$('app-drawer').close(); |
| 185 }, | 173 }, |
| 186 | 174 |
| 187 /** @private */ | 175 /** @private */ |
| 188 onMenuButtonTap_: function() { | 176 onMenuButtonTap_: function() { |
| 189 this.$$('app-drawer').toggle(); | 177 this.$$('app-drawer').toggle(); |
| 190 }, | 178 }, |
| 191 | 179 |
| 192 /** @private */ | 180 /** @private */ |
| 193 directionDelegateChanged_: function() { | 181 directionDelegateChanged_: function() { |
| 194 this.$$('app-drawer').align = this.directionDelegate.isRtl() ? | 182 this.$$('app-drawer').align = this.directionDelegate.isRtl() ? |
| 195 'right' : 'left'; | 183 'right' : 'left'; |
| 196 }, | 184 }, |
| 197 }); | 185 }); |
| OLD | NEW |