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

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

Issue 2469393004: MD Settings: Preserve search URL param in subpages. (Closed)
Patch Set: Function params nit. 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
« no previous file with comments | « no previous file | chrome/browser/resources/settings/settings_menu/settings_menu.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 cr.define('settings', function() { 5 cr.define('settings', function() {
6 /** 6 /**
7 * Class for navigable routes. May only be instantiated within this file. 7 * Class for navigable routes. May only be instantiated within this file.
8 * @constructor 8 * @constructor
9 * @param {string} path 9 * @param {string} path
10 * @private 10 * @private
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 311
312 /** @return {boolean} */ 312 /** @return {boolean} */
313 var lastRouteChangeWasPopstate = function() { 313 var lastRouteChangeWasPopstate = function() {
314 return lastRouteChangeWasPopstate_; 314 return lastRouteChangeWasPopstate_;
315 }; 315 };
316 316
317 /** 317 /**
318 * Navigates to a canonical route and pushes a new history entry. 318 * Navigates to a canonical route and pushes a new history entry.
319 * @param {!settings.Route} route 319 * @param {!settings.Route} route
320 * @param {URLSearchParams=} opt_dynamicParameters Navigations to the same 320 * @param {URLSearchParams=} opt_dynamicParameters Navigations to the same
321 * search parameters in a different order will still push to history. 321 * URL parameters in a different order will still push to history.
322 * @param {boolean=} opt_removeSearch Whether to strip the 'search' URL
323 * parameter during navigation. Defaults to false.
322 */ 324 */
323 var navigateTo = function(route, opt_dynamicParameters) { 325 var navigateTo = function(route, opt_dynamicParameters, opt_removeSearch) {
324 var params = opt_dynamicParameters || new URLSearchParams(); 326 var params = opt_dynamicParameters || new URLSearchParams();
327 var removeSearch = !!opt_removeSearch;
328
329 var oldSearchParam = getQueryParameters().get('search') || '';
330 var newSearchParam = params.get('search') || '';
331
332 if (!removeSearch && oldSearchParam && !newSearchParam)
333 params.append('search', oldSearchParam);
325 334
326 var url = route.path; 335 var url = route.path;
327 if (opt_dynamicParameters) { 336 var queryString = params.toString();
328 var queryString = opt_dynamicParameters.toString(); 337 if (queryString)
329 if (queryString) 338 url += '?' + queryString;
330 url += '?' + queryString;
331 }
332 339
333 // History serializes the state, so we don't push the actual route object. 340 // History serializes the state, so we don't push the actual route object.
334 window.history.pushState(currentRoute_.path, '', url); 341 window.history.pushState(currentRoute_.path, '', url);
335 setCurrentRoute(route, params, false); 342 setCurrentRoute(route, params, false);
336 }; 343 };
337 344
338 /** 345 /**
339 * Navigates to the previous route if it has an equal or lesser depth. 346 * Navigates to the previous route if it has an equal or lesser depth.
340 * If there is no previous route in history meeting those requirements, 347 * If there is no previous route in history meeting those requirements,
341 * this navigates to the immediate parent. This will never exit Settings. 348 * this navigates to the immediate parent. This will never exit Settings.
(...skipping 20 matching lines...) Expand all
362 RouteObserverBehavior: RouteObserverBehavior, 369 RouteObserverBehavior: RouteObserverBehavior,
363 getRouteForPath: getRouteForPath, 370 getRouteForPath: getRouteForPath,
364 initializeRouteFromUrl: initializeRouteFromUrl, 371 initializeRouteFromUrl: initializeRouteFromUrl,
365 getCurrentRoute: getCurrentRoute, 372 getCurrentRoute: getCurrentRoute,
366 getQueryParameters: getQueryParameters, 373 getQueryParameters: getQueryParameters,
367 lastRouteChangeWasPopstate: lastRouteChangeWasPopstate, 374 lastRouteChangeWasPopstate: lastRouteChangeWasPopstate,
368 navigateTo: navigateTo, 375 navigateTo: navigateTo,
369 navigateToPreviousRoute: navigateToPreviousRoute, 376 navigateToPreviousRoute: navigateToPreviousRoute,
370 }; 377 };
371 }); 378 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/settings/settings_menu/settings_menu.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698