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-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) { | 68 this.$$('cr-toolbar').addEventListener( |
| 67 this.$$('settings-main').searchContents(e.detail); | 69 'search-changed', this.onSearchChanged_.bind(this)); |
|
Dan Beam
2016/10/26 01:24:36
any reason why we can't do on-search-changed="onSe
dpapad
2016/10/26 01:31:27
Yes, I'll add a comment to make this more obvious.
Dan Beam
2016/10/26 20:50:52
that's a pretty lame work around. why does trigge
dpapad
2016/10/26 21:02:57
Well, you are right that it does not matter anymor
| |
| 68 }.bind(this)); | |
| 69 | 70 |
| 70 // Lazy-create the drawer the first time it is opened or swiped into view. | 71 // Lazy-create the drawer the first time it is opened or swiped into view. |
| 71 var drawer = assert(this.$$('app-drawer')); | 72 var drawer = assert(this.$$('app-drawer')); |
| 72 listenOnce(drawer, 'track opened-changed', function() { | 73 listenOnce(drawer, 'track opened-changed', function() { |
| 73 this.$.drawerTemplate.if = true; | 74 this.$.drawerTemplate.if = true; |
| 74 }.bind(this)); | 75 }.bind(this)); |
| 75 | 76 |
| 76 window.addEventListener('popstate', function(e) { | 77 window.addEventListener('popstate', function(e) { |
| 77 drawer.close(); | 78 drawer.close(); |
| 78 }.bind(this)); | 79 }.bind(this)); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 109 } | 110 } |
| 110 }, | 111 }, |
| 111 | 112 |
| 112 /** @override */ | 113 /** @override */ |
| 113 attached: function() { | 114 attached: function() { |
| 114 // Preload bold Roboto so it doesn't load and flicker the first time used. | 115 // Preload bold Roboto so it doesn't load and flicker the first time used. |
| 115 document.fonts.load('bold 12px Roboto'); | 116 document.fonts.load('bold 12px Roboto'); |
| 116 settings.setGlobalScrollTarget(this.$.headerPanel.scroller); | 117 settings.setGlobalScrollTarget(this.$.headerPanel.scroller); |
| 117 }, | 118 }, |
| 118 | 119 |
| 120 /** @param {!settings.Route} newRoute */ | |
| 121 currentRouteChanged: function(newRoute) { | |
| 122 var searchQuery = settings.getQueryParameters().get('search') || ''; | |
| 123 var toolbar = /** @type {!CrToolbarElement} */ (this.$$('cr-toolbar')); | |
| 124 var searchField = /** @type {CrToolbarSearchFieldElement} */ ( | |
| 125 toolbar.getSearchField()); | |
| 126 searchField.setValue(searchQuery); | |
| 127 }, | |
| 128 | |
| 129 /** | |
| 130 * @param {!Event} e | |
| 131 * @private | |
| 132 */ | |
| 133 onSearchChanged_: function(e) { | |
| 134 var query = e.detail; | |
| 135 | |
| 136 // 'search-changed' event was fired only because the search box's value was | |
| 137 // updated to reflect the already existing search URL parameter, no need to | |
| 138 // navigate again. | |
| 139 var existingQuery = settings.getQueryParameters().get('search') || ''; | |
| 140 if (query == existingQuery) | |
| 141 return; | |
| 142 | |
| 143 settings.navigateTo( | |
| 144 settings.Route.BASIC, | |
| 145 query.length > 0 ? new URLSearchParams(`search=${query}`) : undefined); | |
| 146 }, | |
| 147 | |
| 119 /** | 148 /** |
| 120 * @param {Event} event | 149 * @param {Event} event |
| 121 * @private | 150 * @private |
| 122 */ | 151 */ |
| 123 onIronActivate_: function(event) { | 152 onIronActivate_: function(event) { |
| 124 if (event.detail.item.id != 'advancedPage') | 153 if (event.detail.item.id != 'advancedPage') |
| 125 this.$$('app-drawer').close(); | 154 this.$$('app-drawer').close(); |
| 126 }, | 155 }, |
| 127 | 156 |
| 128 /** @private */ | 157 /** @private */ |
| 129 onMenuButtonTap_: function() { | 158 onMenuButtonTap_: function() { |
| 130 this.$$('app-drawer').toggle(); | 159 this.$$('app-drawer').toggle(); |
| 131 }, | 160 }, |
| 132 | 161 |
| 133 /** @private */ | 162 /** @private */ |
| 134 directionDelegateChanged_: function() { | 163 directionDelegateChanged_: function() { |
| 135 this.$$('app-drawer').align = this.directionDelegate.isRtl() ? | 164 this.$$('app-drawer').align = this.directionDelegate.isRtl() ? |
| 136 'right' : 'left'; | 165 'right' : 'left'; |
| 137 }, | 166 }, |
| 138 }); | 167 }); |
| OLD | NEW |