| 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 * |
| 11 * <settings-ui prefs="{{prefs}}"></settings-ui> | 11 * <settings-ui prefs="{{prefs}}"></settings-ui> |
| 12 */ | 12 */ |
| 13 cr.exportPath('settings'); | 13 cr.exportPath('settings'); |
| 14 assert(!settings.defaultResourceLoaded, | 14 assert(!settings.defaultResourceLoaded, |
| 15 'settings_ui.js run twice. You probably have an invalid import.'); | 15 'settings_ui.js run twice. You probably have an invalid import.'); |
| 16 /** Global defined when the main Settings script runs. */ | 16 /** Global defined when the main Settings script runs. */ |
| 17 settings.defaultResourceLoaded = true; | 17 settings.defaultResourceLoaded = true; |
| 18 | 18 |
| 19 Polymer({ | 19 Polymer({ |
| 20 is: 'settings-ui', | 20 is: 'settings-ui', |
| 21 | 21 |
| 22 behaviors: [settings.RouteObserverBehavior], |
| 23 |
| 22 properties: { | 24 properties: { |
| 23 /** | 25 /** |
| 24 * Preferences state. | 26 * Preferences state. |
| 25 */ | 27 */ |
| 26 prefs: Object, | 28 prefs: Object, |
| 27 | 29 |
| 28 /** @type {?settings.DirectionDelegate} */ | 30 /** @type {?settings.DirectionDelegate} */ |
| 29 directionDelegate: { | 31 directionDelegate: { |
| 30 observer: 'directionDelegateChanged_', | 32 observer: 'directionDelegateChanged_', |
| 31 type: Object, | 33 type: Object, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 43 toolbarSpinnerActive_: { | 45 toolbarSpinnerActive_: { |
| 44 type: Boolean, | 46 type: Boolean, |
| 45 value: false, | 47 value: false, |
| 46 }, | 48 }, |
| 47 | 49 |
| 48 /** | 50 /** |
| 49 * Dictionary defining page visibility. | 51 * Dictionary defining page visibility. |
| 50 * @private {!GuestModePageVisibility} | 52 * @private {!GuestModePageVisibility} |
| 51 */ | 53 */ |
| 52 pageVisibility_: Object, | 54 pageVisibility_: Object, |
| 55 |
| 56 /** @private */ |
| 57 lastSearchQuery_: { |
| 58 type: String, |
| 59 value: '', |
| 60 } |
| 53 }, | 61 }, |
| 54 | 62 |
| 55 /** @override */ | 63 /** @override */ |
| 56 created: function() { | 64 created: function() { |
| 57 settings.initializeRouteFromUrl(); | 65 settings.initializeRouteFromUrl(); |
| 58 }, | 66 }, |
| 59 | 67 |
| 60 /** | 68 /** |
| 61 * @override | 69 * @override |
| 62 * @suppress {es5Strict} Object literals cannot contain duplicate keys in ES5 | 70 * @suppress {es5Strict} Object literals cannot contain duplicate keys in ES5 |
| 63 * strict mode. | 71 * strict mode. |
| 64 */ | 72 */ |
| 65 ready: function() { | 73 ready: function() { |
| 66 this.$$('cr-toolbar').addEventListener('search-changed', function(e) { | |
| 67 this.$$('settings-main').searchContents(e.detail); | |
| 68 }.bind(this)); | |
| 69 | |
| 70 // Lazy-create the drawer the first time it is opened or swiped into view. | 74 // Lazy-create the drawer the first time it is opened or swiped into view. |
| 71 var drawer = assert(this.$$('app-drawer')); | 75 var drawer = assert(this.$$('app-drawer')); |
| 72 listenOnce(drawer, 'track opened-changed', function() { | 76 listenOnce(drawer, 'track opened-changed', function() { |
| 73 this.$.drawerTemplate.if = true; | 77 this.$.drawerTemplate.if = true; |
| 74 }.bind(this)); | 78 }.bind(this)); |
| 75 | 79 |
| 76 window.addEventListener('popstate', function(e) { | 80 window.addEventListener('popstate', function(e) { |
| 77 drawer.close(); | 81 drawer.close(); |
| 78 }.bind(this)); | 82 }.bind(this)); |
| 79 | 83 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 109 } | 113 } |
| 110 }, | 114 }, |
| 111 | 115 |
| 112 /** @override */ | 116 /** @override */ |
| 113 attached: function() { | 117 attached: function() { |
| 114 // 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. |
| 115 document.fonts.load('bold 12px Roboto'); | 119 document.fonts.load('bold 12px Roboto'); |
| 116 settings.setGlobalScrollTarget(this.$.headerPanel.scroller); | 120 settings.setGlobalScrollTarget(this.$.headerPanel.scroller); |
| 117 }, | 121 }, |
| 118 | 122 |
| 123 /** @param {!settings.Route} 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') || ''; |
| 138 if (urlSearchQuery == this.lastSearchQuery_) |
| 139 return; |
| 140 |
| 141 this.lastSearchQuery_ = urlSearchQuery; |
| 142 |
| 143 var toolbar = /** @type {!CrToolbarElement} */ (this.$$('cr-toolbar')); |
| 144 var searchField = /** @type {CrToolbarSearchFieldElement} */ ( |
| 145 toolbar.getSearchField()); |
| 146 |
| 147 // If the search was initiated by directly entering a search URL, need to |
| 148 // sync the URL parameter to the textbox. |
| 149 if (urlSearchQuery != searchField.getValue()) { |
| 150 // Setting the search box value without triggering a 'search-changed' |
| 151 // event, to prevent an unnecessary duplicate entry in |window.history|. |
| 152 searchField.setValue(urlSearchQuery, true /* noEvent */); |
| 153 } |
| 154 |
| 155 this.$.main.searchContents(urlSearchQuery); |
| 156 }, |
| 157 |
| 158 /** |
| 159 * Handles the 'search-changed' event fired from the toolbar. |
| 160 * @param {!Event} e |
| 161 * @private |
| 162 */ |
| 163 onSearchChanged_: function(e) { |
| 164 var query = e.detail; |
| 165 settings.navigateTo( |
| 166 settings.Route.BASIC, |
| 167 query.length > 0 ? |
| 168 new URLSearchParams(`search=${query}`) : undefined); |
| 169 }, |
| 170 |
| 119 /** | 171 /** |
| 120 * @param {Event} event | 172 * @param {Event} event |
| 121 * @private | 173 * @private |
| 122 */ | 174 */ |
| 123 onIronActivate_: function(event) { | 175 onIronActivate_: function(event) { |
| 124 if (event.detail.item.id != 'advancedPage') | 176 if (event.detail.item.id != 'advancedPage') |
| 125 this.$$('app-drawer').close(); | 177 this.$$('app-drawer').close(); |
| 126 }, | 178 }, |
| 127 | 179 |
| 128 /** @private */ | 180 /** @private */ |
| 129 onMenuButtonTap_: function() { | 181 onMenuButtonTap_: function() { |
| 130 this.$$('app-drawer').toggle(); | 182 this.$$('app-drawer').toggle(); |
| 131 }, | 183 }, |
| 132 | 184 |
| 133 /** @private */ | 185 /** @private */ |
| 134 directionDelegateChanged_: function() { | 186 directionDelegateChanged_: function() { |
| 135 this.$$('app-drawer').align = this.directionDelegate.isRtl() ? | 187 this.$$('app-drawer').align = this.directionDelegate.isRtl() ? |
| 136 'right' : 'left'; | 188 'right' : 'left'; |
| 137 }, | 189 }, |
| 138 }); | 190 }); |
| OLD | NEW |