| 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 24 matching lines...) Expand all Loading... |
| 56 created: function() { | 58 created: function() { |
| 57 settings.initializeRouteFromUrl(); | 59 settings.initializeRouteFromUrl(); |
| 58 }, | 60 }, |
| 59 | 61 |
| 60 /** | 62 /** |
| 61 * @override | 63 * @override |
| 62 * @suppress {es5Strict} Object literals cannot contain duplicate keys in ES5 | 64 * @suppress {es5Strict} Object literals cannot contain duplicate keys in ES5 |
| 63 * strict mode. | 65 * strict mode. |
| 64 */ | 66 */ |
| 65 ready: function() { | 67 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. | 68 // Lazy-create the drawer the first time it is opened or swiped into view. |
| 71 var drawer = assert(this.$$('app-drawer')); | 69 var drawer = assert(this.$$('app-drawer')); |
| 72 listenOnce(drawer, 'track opened-changed', function() { | 70 listenOnce(drawer, 'track opened-changed', function() { |
| 73 this.$.drawerTemplate.if = true; | 71 this.$.drawerTemplate.if = true; |
| 74 }.bind(this)); | 72 }.bind(this)); |
| 75 | 73 |
| 76 window.addEventListener('popstate', function(e) { | 74 window.addEventListener('popstate', function(e) { |
| 77 drawer.close(); | 75 drawer.close(); |
| 78 }.bind(this)); | 76 }.bind(this)); |
| 79 | 77 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 109 } | 107 } |
| 110 }, | 108 }, |
| 111 | 109 |
| 112 /** @override */ | 110 /** @override */ |
| 113 attached: function() { | 111 attached: function() { |
| 114 // Preload bold Roboto so it doesn't load and flicker the first time used. | 112 // Preload bold Roboto so it doesn't load and flicker the first time used. |
| 115 document.fonts.load('bold 12px Roboto'); | 113 document.fonts.load('bold 12px Roboto'); |
| 116 settings.setGlobalScrollTarget(this.$.headerPanel.scroller); | 114 settings.setGlobalScrollTarget(this.$.headerPanel.scroller); |
| 117 }, | 115 }, |
| 118 | 116 |
| 117 /** @param {!settings.Route} newRoute */ |
| 118 currentRouteChanged: function(newRoute) { |
| 119 var searchQuery = settings.getQueryParameters().get('search') || ''; |
| 120 var toolbar = /** @type {!CrToolbarElement} */ (this.$$('cr-toolbar')); |
| 121 var searchField = /** @type {CrToolbarSearchFieldElement} */ ( |
| 122 toolbar.getSearchField()); |
| 123 searchField.setValue(searchQuery); |
| 124 }, |
| 125 |
| 126 /** |
| 127 * @param {!Event} e |
| 128 * @private |
| 129 */ |
| 130 onSearchChanged_: function(e) { |
| 131 var query = e.detail; |
| 132 |
| 133 // 'search-changed' event was fired only because the search box's value was |
| 134 // updated to reflect the already existing search URL parameter, no need to |
| 135 // navigate again. |
| 136 var existingQuery = settings.getQueryParameters().get('search') || ''; |
| 137 if (query == existingQuery) |
| 138 return; |
| 139 |
| 140 settings.navigateTo( |
| 141 settings.Route.BASIC, |
| 142 query.length > 0 ? new URLSearchParams(`search=${query}`) : undefined); |
| 143 }, |
| 144 |
| 119 /** | 145 /** |
| 120 * @param {Event} event | 146 * @param {Event} event |
| 121 * @private | 147 * @private |
| 122 */ | 148 */ |
| 123 onIronActivate_: function(event) { | 149 onIronActivate_: function(event) { |
| 124 if (event.detail.item.id != 'advancedPage') | 150 if (event.detail.item.id != 'advancedPage') |
| 125 this.$$('app-drawer').close(); | 151 this.$$('app-drawer').close(); |
| 126 }, | 152 }, |
| 127 | 153 |
| 128 /** @private */ | 154 /** @private */ |
| 129 onMenuButtonTap_: function() { | 155 onMenuButtonTap_: function() { |
| 130 this.$$('app-drawer').toggle(); | 156 this.$$('app-drawer').toggle(); |
| 131 }, | 157 }, |
| 132 | 158 |
| 133 /** @private */ | 159 /** @private */ |
| 134 directionDelegateChanged_: function() { | 160 directionDelegateChanged_: function() { |
| 135 this.$$('app-drawer').align = this.directionDelegate.isRtl() ? | 161 this.$$('app-drawer').align = this.directionDelegate.isRtl() ? |
| 136 'right' : 'left'; | 162 'right' : 'left'; |
| 137 }, | 163 }, |
| 138 }); | 164 }); |
| OLD | NEW |