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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 | 290 |
| 291 return Route[matchingKey] || null; | 291 return Route[matchingKey] || null; |
| 292 }; | 292 }; |
| 293 | 293 |
| 294 /** | 294 /** |
| 295 * The current active route. This may only be updated via the global | 295 * The current active route. This may only be updated via the global |
| 296 * function settings.navigateTo. | 296 * function settings.navigateTo. |
| 297 * @private {!settings.Route} | 297 * @private {!settings.Route} |
| 298 */ | 298 */ |
| 299 var currentRoute_ = getRouteForPath(window.location.pathname) || Route.BASIC; | 299 var currentRoute_ = getRouteForPath(window.location.pathname) || Route.BASIC; |
| 300 window.history.replaceState(undefined, '', currentRoute_.path); | |
|
Dan Beam
2016/08/01 23:39:19
can we do this only if currentRoute_ is null?
tommycli
2016/08/02 00:00:39
Done.
| |
| 300 | 301 |
| 301 /** | 302 /** |
| 302 * Helper function to set the current route and notify all observers. | 303 * Helper function to set the current route and notify all observers. |
| 303 * @param {!settings.Route} route | 304 * @param {!settings.Route} route |
| 304 */ | 305 */ |
| 305 var setCurrentRoute = function(route) { | 306 var setCurrentRoute = function(route) { |
| 306 currentRoute_ = route; | 307 currentRoute_ = route; |
| 307 for (var observer of routeObservers_) | 308 for (var observer of routeObservers_) |
| 308 observer.currentRouteChanged(); | 309 observer.currentRouteChanged(); |
| 309 }; | 310 }; |
| 310 | 311 |
| 311 /** @return {!settings.Route} */ | 312 /** @return {!settings.Route} */ |
| 312 var getCurrentRoute = function() { return currentRoute_; }; | 313 var getCurrentRoute = function() { return currentRoute_; }; |
| 313 | 314 |
| 314 /** | 315 /** |
| 315 * Navigates to a canonical route and pushes a new history entry. | 316 * Navigates to a canonical route and pushes a new history entry. |
| 316 * @param {!settings.Route} route | 317 * @param {!settings.Route} route |
| 317 * @private | 318 * @private |
| 318 */ | 319 */ |
| 319 var navigateTo = function(route) { | 320 var navigateTo = function(route) { |
| 320 if (assert(route) == currentRoute_) | 321 if (assert(route) == currentRoute_) |
| 321 return; | 322 return; |
| 322 | 323 |
| 323 window.history.pushState(undefined, document.title, route.path); | 324 window.history.pushState(undefined, '', route.path); |
|
tommycli
2016/08/01 23:38:18
It's unused (by both Firefox and Chrome), and MDN
Dan Beam
2016/08/01 23:39:19
Acknowledged.
| |
| 324 setCurrentRoute(route); | 325 setCurrentRoute(route); |
| 325 }; | 326 }; |
| 326 | 327 |
| 327 window.addEventListener('popstate', function(event) { | 328 window.addEventListener('popstate', function(event) { |
| 328 // On pop state, do not push the state onto the window.history again. | 329 // On pop state, do not push the state onto the window.history again. |
| 329 setCurrentRoute(getRouteForPath(window.location.pathname) || Route.BASIC); | 330 setCurrentRoute(getRouteForPath(window.location.pathname) || Route.BASIC); |
| 330 }); | 331 }); |
| 331 | 332 |
| 332 return { | 333 return { |
| 333 Route: Route, | 334 Route: Route, |
| 334 RouteObserverBehavior: RouteObserverBehavior, | 335 RouteObserverBehavior: RouteObserverBehavior, |
| 335 getRouteForPath: getRouteForPath, | 336 getRouteForPath: getRouteForPath, |
| 336 getCurrentRoute: getCurrentRoute, | 337 getCurrentRoute: getCurrentRoute, |
| 337 navigateTo: navigateTo, | 338 navigateTo: navigateTo, |
| 338 }; | 339 }; |
| 339 }); | 340 }); |
| OLD | NEW |