Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: chrome/browser/resources/settings/settings_ui/settings_ui.js

Issue 2449663002: MD Settings: Implement search URLs. (Closed)
Patch Set: Rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 /**
57 * The latest search query. Setting this value triggers a search via binding
58 * with <settings-main> element.
59 * @private
60 */
61 searchQuery_: {
62 type: String,
63 value: '',
64 },
53 }, 65 },
54 66
55 /** @override */ 67 /** @override */
56 created: function() { 68 created: function() {
57 settings.initializeRouteFromUrl(); 69 settings.initializeRouteFromUrl();
58 }, 70 },
59 71
60 /** 72 /**
61 * @override 73 * @override
62 * @suppress {es5Strict} Object literals cannot contain duplicate keys in ES5 74 * @suppress {es5Strict} Object literals cannot contain duplicate keys in ES5
63 * strict mode. 75 * strict mode.
64 */ 76 */
65 ready: function() { 77 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. 78 // Lazy-create the drawer the first time it is opened or swiped into view.
71 var drawer = assert(this.$$('app-drawer')); 79 var drawer = assert(this.$$('app-drawer'));
72 listenOnce(drawer, 'track opened-changed', function() { 80 listenOnce(drawer, 'track opened-changed', function() {
73 this.$.drawerTemplate.if = true; 81 this.$.drawerTemplate.if = true;
74 }.bind(this)); 82 }.bind(this));
75 83
76 window.addEventListener('popstate', function(e) { 84 window.addEventListener('popstate', function(e) {
77 drawer.close(); 85 drawer.close();
78 }.bind(this)); 86 }.bind(this));
79 87
(...skipping 29 matching lines...) Expand all
109 } 117 }
110 }, 118 },
111 119
112 /** @override */ 120 /** @override */
113 attached: function() { 121 attached: function() {
114 // Preload bold Roboto so it doesn't load and flicker the first time used. 122 // Preload bold Roboto so it doesn't load and flicker the first time used.
115 document.fonts.load('bold 12px Roboto'); 123 document.fonts.load('bold 12px Roboto');
116 settings.setGlobalScrollTarget(this.$.headerPanel.scroller); 124 settings.setGlobalScrollTarget(this.$.headerPanel.scroller);
117 }, 125 },
118 126
127 /** @param {!settings.Route} route */
128 currentRouteChanged: function(route) {
129 // When navigating into a subpage, search highlights have already been
130 // applied (if any), no further action should be taken.
tommycli 2016/11/01 21:05:26 optional: may also be worth pointing out that all
dpapad 2016/11/01 22:02:02 Rephrased the comment per your suggestion. Also ad
131 if (route.isSubpage())
132 return;
133
134 var urlSearchQuery = settings.getQueryParameters().get('search') || '';
135 var toolbar = /** @type {!CrToolbarElement} */ (this.$$('cr-toolbar'));
136 var searchField = /** @type {CrToolbarSearchFieldElement} */ (
137 toolbar.getSearchField());
138
139 // If the search was initiated by directly entering a search URL, need to
140 // sync the URL parameter to the textbox.
141 if (urlSearchQuery != searchField.getValue()) {
142 // Setting the search box value without triggering a 'search-changed'
143 // event, to prevent an unnecessary duplicate entry in |window.history|.
144 searchField.setValue(urlSearchQuery, true /* noEvent */);
145 }
146
147 // Trigger search via data binding.
148 this.searchQuery_ = urlSearchQuery;
tommycli 2016/11/01 21:05:26 Yeah the more I look at it, the more I think we ca
dpapad 2016/11/01 22:02:02 Done.
149 },
150
151 /**
152 * Handles the 'search-changed' event fired from the toolbar.
153 * @param {!Event} e
154 * @private
155 */
156 onSearchChanged_: function(e) {
157 var query = e.detail;
158 settings.navigateTo(
159 settings.Route.BASIC,
160 query.length > 0 ?
161 new URLSearchParams(`search=${query}`) : undefined);
162 },
163
119 /** 164 /**
120 * @param {Event} event 165 * @param {Event} event
121 * @private 166 * @private
122 */ 167 */
123 onIronActivate_: function(event) { 168 onIronActivate_: function(event) {
124 if (event.detail.item.id != 'advancedPage') 169 if (event.detail.item.id != 'advancedPage')
125 this.$$('app-drawer').close(); 170 this.$$('app-drawer').close();
126 }, 171 },
127 172
128 /** @private */ 173 /** @private */
129 onMenuButtonTap_: function() { 174 onMenuButtonTap_: function() {
130 this.$$('app-drawer').toggle(); 175 this.$$('app-drawer').toggle();
131 }, 176 },
132 177
133 /** @private */ 178 /** @private */
134 directionDelegateChanged_: function() { 179 directionDelegateChanged_: function() {
135 this.$$('app-drawer').align = this.directionDelegate.isRtl() ? 180 this.$$('app-drawer').align = this.directionDelegate.isRtl() ?
136 'right' : 'left'; 181 'right' : 'left';
137 }, 182 },
138 }); 183 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698