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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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_preserveSearch Whether to preserve the 'search' URL | |
| 323 * parameter during navigation. Defaults to true if not provided. | |
| 322 */ | 324 */ |
| 323 var navigateTo = function(route, opt_dynamicParameters) { | 325 var navigateTo = function(route, opt_dynamicParameters, opt_preserveSearch) { |
| 324 var params = opt_dynamicParameters || new URLSearchParams(); | 326 var params = opt_dynamicParameters || new URLSearchParams(); |
| 327 var preserveSearch = opt_preserveSearch == undefined ? | |
|
dschuyler
2016/11/09 23:10:14
Can we go with either
!opt_preserveSearch
or
opt
dpapad
2016/11/09 23:19:15
Default value of opt_preserveSearch is true, if th
| |
| 328 true : !!opt_preserveSearch; | |
| 329 | |
| 330 var oldSearchParam = getQueryParameters().get('search') || ''; | |
| 331 var newSearchParam = params.get('search') || ''; | |
| 332 | |
| 333 if (preserveSearch && oldSearchParam && !newSearchParam) | |
| 334 params.append('search', oldSearchParam); | |
| 325 | 335 |
| 326 var url = route.path; | 336 var url = route.path; |
| 327 if (opt_dynamicParameters) { | 337 var queryString = params.toString(); |
| 328 var queryString = opt_dynamicParameters.toString(); | 338 if (queryString) |
| 329 if (queryString) | 339 url += '?' + queryString; |
| 330 url += '?' + queryString; | |
| 331 } | |
| 332 | 340 |
| 333 // History serializes the state, so we don't push the actual route object. | 341 // History serializes the state, so we don't push the actual route object. |
| 334 window.history.pushState(currentRoute_.path, '', url); | 342 window.history.pushState(currentRoute_.path, '', url); |
| 335 setCurrentRoute(route, params, false); | 343 setCurrentRoute(route, params, false); |
| 336 }; | 344 }; |
| 337 | 345 |
| 338 /** | 346 /** |
| 339 * Navigates to the previous route if it has an equal or lesser depth. | 347 * 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, | 348 * If there is no previous route in history meeting those requirements, |
| 341 * this navigates to the immediate parent. This will never exit Settings. | 349 * this navigates to the immediate parent. This will never exit Settings. |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 362 RouteObserverBehavior: RouteObserverBehavior, | 370 RouteObserverBehavior: RouteObserverBehavior, |
| 363 getRouteForPath: getRouteForPath, | 371 getRouteForPath: getRouteForPath, |
| 364 initializeRouteFromUrl: initializeRouteFromUrl, | 372 initializeRouteFromUrl: initializeRouteFromUrl, |
| 365 getCurrentRoute: getCurrentRoute, | 373 getCurrentRoute: getCurrentRoute, |
| 366 getQueryParameters: getQueryParameters, | 374 getQueryParameters: getQueryParameters, |
| 367 lastRouteChangeWasPopstate: lastRouteChangeWasPopstate, | 375 lastRouteChangeWasPopstate: lastRouteChangeWasPopstate, |
| 368 navigateTo: navigateTo, | 376 navigateTo: navigateTo, |
| 369 navigateToPreviousRoute: navigateToPreviousRoute, | 377 navigateToPreviousRoute: navigateToPreviousRoute, |
| 370 }; | 378 }; |
| 371 }); | 379 }); |
| OLD | NEW |