| 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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 if (queryString) | 310 if (queryString) |
| 311 url += '?' + queryString; | 311 url += '?' + queryString; |
| 312 } | 312 } |
| 313 | 313 |
| 314 // History serializes the state, so we don't push the actual route object. | 314 // History serializes the state, so we don't push the actual route object. |
| 315 window.history.pushState(currentRoute_.path, '', url); | 315 window.history.pushState(currentRoute_.path, '', url); |
| 316 setCurrentRoute(route, params); | 316 setCurrentRoute(route, params); |
| 317 }; | 317 }; |
| 318 | 318 |
| 319 /** | 319 /** |
| 320 * Navigates to the previous route, but will never exit Settings. If there is | 320 * Navigates to the previous route if it has an equal or lesser depth. |
| 321 * no previous route in the history, navigates to the immediate parent. | 321 * If there is no previous route in history meeting those requirements, |
| 322 * this navigates to the immediate parent. This will never exit Settings. |
| 322 */ | 323 */ |
| 323 var navigateToPreviousRoute = function() { | 324 var navigateToPreviousRoute = function() { |
| 324 var previousRoute = | 325 var previousRoute = |
| 325 window.history.state && | 326 window.history.state && |
| 326 assert(getRouteForPath(/** @type {string} */ (window.history.state))); | 327 assert(getRouteForPath(/** @type {string} */ (window.history.state))); |
| 327 | 328 |
| 328 if (previousRoute) | 329 if (previousRoute && previousRoute.depth <= currentRoute_.depth) |
| 329 window.history.back(); | 330 window.history.back(); |
| 330 else | 331 else |
| 331 navigateTo(settings.getCurrentRoute().parent || Route.BASIC); | 332 navigateTo(currentRoute_.parent || Route.BASIC); |
| 332 }; | 333 }; |
| 333 | 334 |
| 334 window.addEventListener('popstate', function(event) { | 335 window.addEventListener('popstate', function(event) { |
| 335 // On pop state, do not push the state onto the window.history again. | 336 // On pop state, do not push the state onto the window.history again. |
| 336 setCurrentRoute(getRouteForPath(window.location.pathname) || Route.BASIC, | 337 setCurrentRoute(getRouteForPath(window.location.pathname) || Route.BASIC, |
| 337 new URLSearchParams(window.location.search)); | 338 new URLSearchParams(window.location.search)); |
| 338 }); | 339 }); |
| 339 | 340 |
| 340 return { | 341 return { |
| 341 Route: Route, | 342 Route: Route, |
| 342 RouteObserverBehavior: RouteObserverBehavior, | 343 RouteObserverBehavior: RouteObserverBehavior, |
| 343 getRouteForPath: getRouteForPath, | 344 getRouteForPath: getRouteForPath, |
| 344 initializeRouteFromUrl: initializeRouteFromUrl, | 345 initializeRouteFromUrl: initializeRouteFromUrl, |
| 345 getCurrentRoute: getCurrentRoute, | 346 getCurrentRoute: getCurrentRoute, |
| 346 getQueryParameters: getQueryParameters, | 347 getQueryParameters: getQueryParameters, |
| 347 navigateTo: navigateTo, | 348 navigateTo: navigateTo, |
| 348 navigateToPreviousRoute: navigateToPreviousRoute, | 349 navigateToPreviousRoute: navigateToPreviousRoute, |
| 349 }; | 350 }; |
| 350 }); | 351 }); |
| OLD | NEW |