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

Unified Diff: chrome/browser/resources/settings/settings_ui/settings_ui.js

Issue 2449663002: MD Settings: Implement search URLs. (Closed)
Patch Set: Rebase Created 4 years, 2 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/settings/settings_ui/settings_ui.js
diff --git a/chrome/browser/resources/settings/settings_ui/settings_ui.js b/chrome/browser/resources/settings/settings_ui/settings_ui.js
index f14a509792380ed6a0957c0fc8c11ef4853aaabd..bb5ca2ddc0deb4f2c020713477def3be18c88855 100644
--- a/chrome/browser/resources/settings/settings_ui/settings_ui.js
+++ b/chrome/browser/resources/settings/settings_ui/settings_ui.js
@@ -19,6 +19,8 @@ settings.defaultResourceLoaded = true;
Polymer({
is: 'settings-ui',
+ behaviors: [settings.RouteObserverBehavior],
+
properties: {
/**
* Preferences state.
@@ -50,6 +52,16 @@ Polymer({
* @private {!GuestModePageVisibility}
*/
pageVisibility_: Object,
+
+ /**
+ * The latest search query. Setting this value triggers a search via binding
+ * with <settings-main> element.
+ * @private
+ */
+ searchQuery_: {
+ type: String,
+ value: '',
+ },
},
/** @override */
@@ -63,10 +75,6 @@ Polymer({
* strict mode.
*/
ready: function() {
- this.$$('cr-toolbar').addEventListener('search-changed', function(e) {
- this.$$('settings-main').searchContents(e.detail);
- }.bind(this));
-
// Lazy-create the drawer the first time it is opened or swiped into view.
var drawer = assert(this.$$('app-drawer'));
listenOnce(drawer, 'track opened-changed', function() {
@@ -116,6 +124,43 @@ Polymer({
settings.setGlobalScrollTarget(this.$.headerPanel.scroller);
},
+ /** @param {!settings.Route} route */
+ currentRouteChanged: function(route) {
+ // When navigating into a subpage, search highlights have already been
+ // 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
+ if (route.isSubpage())
+ return;
+
+ var urlSearchQuery = settings.getQueryParameters().get('search') || '';
+ var toolbar = /** @type {!CrToolbarElement} */ (this.$$('cr-toolbar'));
+ var searchField = /** @type {CrToolbarSearchFieldElement} */ (
+ toolbar.getSearchField());
+
+ // If the search was initiated by directly entering a search URL, need to
+ // sync the URL parameter to the textbox.
+ if (urlSearchQuery != searchField.getValue()) {
+ // Setting the search box value without triggering a 'search-changed'
+ // event, to prevent an unnecessary duplicate entry in |window.history|.
+ searchField.setValue(urlSearchQuery, true /* noEvent */);
+ }
+
+ // Trigger search via data binding.
+ 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.
+ },
+
+ /**
+ * Handles the 'search-changed' event fired from the toolbar.
+ * @param {!Event} e
+ * @private
+ */
+ onSearchChanged_: function(e) {
+ var query = e.detail;
+ settings.navigateTo(
+ settings.Route.BASIC,
+ query.length > 0 ?
+ new URLSearchParams(`search=${query}`) : undefined);
+ },
+
/**
* @param {Event} event
* @private

Powered by Google App Engine
This is Rietveld 408576698