Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 * search parameters in a different order will still push to history. |
| 322 */ | 322 */ |
| 323 var navigateTo = function(route, opt_dynamicParameters) { | 323 var navigateTo = function(route, opt_dynamicParameters, opt_preserveSearch) { |
| 324 var currentParams = getQueryParameters(); | |
| 325 var oldSearchParam = currentParams.get('search') || ''; | |
| 326 | |
| 324 var params = opt_dynamicParameters || new URLSearchParams(); | 327 var params = opt_dynamicParameters || new URLSearchParams(); |
| 328 var newSearchParam = params.get('search') || ''; | |
| 325 | 329 |
| 326 var url = route.path; | 330 var url = route.path; |
| 327 if (opt_dynamicParameters) { | 331 if (opt_dynamicParameters) { |
| 328 var queryString = opt_dynamicParameters.toString(); | 332 var queryString = opt_dynamicParameters.toString(); |
| 329 if (queryString) | 333 if (queryString) |
| 330 url += '?' + queryString; | 334 url += '?' + queryString; |
| 331 } | 335 } |
| 332 | 336 |
| 337 var preserveSearch = opt_preserveSearch == undefined ? | |
| 338 true : !!opt_preserveSearch; | |
| 339 if (preserveSearch && oldSearchParam.length > 0 && | |
| 340 newSearchParam.length == 0) { | |
| 341 url += '?' + `search=${oldSearchParam}`; | |
| 342 params.append('search', oldSearchParam); | |
| 343 } | |
| 344 | |
|
tommycli
2016/11/03 23:31:33
I would recommend doing something like this on lin
dpapad
2016/11/04 02:00:33
Done. I also removed the "if (opt_dynamicParameter
| |
| 333 // History serializes the state, so we don't push the actual route object. | 345 // History serializes the state, so we don't push the actual route object. |
| 334 window.history.pushState(currentRoute_.path, '', url); | 346 window.history.pushState(currentRoute_.path, '', url); |
| 335 setCurrentRoute(route, params, false); | 347 setCurrentRoute(route, params, false); |
| 336 }; | 348 }; |
| 337 | 349 |
| 338 /** | 350 /** |
| 339 * Navigates to the previous route if it has an equal or lesser depth. | 351 * 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, | 352 * If there is no previous route in history meeting those requirements, |
| 341 * this navigates to the immediate parent. This will never exit Settings. | 353 * this navigates to the immediate parent. This will never exit Settings. |
| 342 */ | 354 */ |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 362 RouteObserverBehavior: RouteObserverBehavior, | 374 RouteObserverBehavior: RouteObserverBehavior, |
| 363 getRouteForPath: getRouteForPath, | 375 getRouteForPath: getRouteForPath, |
| 364 initializeRouteFromUrl: initializeRouteFromUrl, | 376 initializeRouteFromUrl: initializeRouteFromUrl, |
| 365 getCurrentRoute: getCurrentRoute, | 377 getCurrentRoute: getCurrentRoute, |
| 366 getQueryParameters: getQueryParameters, | 378 getQueryParameters: getQueryParameters, |
| 367 lastRouteChangeWasPopstate: lastRouteChangeWasPopstate, | 379 lastRouteChangeWasPopstate: lastRouteChangeWasPopstate, |
| 368 navigateTo: navigateTo, | 380 navigateTo: navigateTo, |
| 369 navigateToPreviousRoute: navigateToPreviousRoute, | 381 navigateToPreviousRoute: navigateToPreviousRoute, |
| 370 }; | 382 }; |
| 371 }); | 383 }); |
| OLD | NEW |