| 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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 * @param {!settings.Route|undefined} opt_newRoute | 231 * @param {!settings.Route|undefined} opt_newRoute |
| 232 * @param {!settings.Route|undefined} opt_oldRoute | 232 * @param {!settings.Route|undefined} opt_oldRoute |
| 233 * @abstract | 233 * @abstract |
| 234 */ | 234 */ |
| 235 currentRouteChanged: function(opt_newRoute, opt_oldRoute) { | 235 currentRouteChanged: function(opt_newRoute, opt_oldRoute) { |
| 236 assertNotReached(); | 236 assertNotReached(); |
| 237 }, | 237 }, |
| 238 }; | 238 }; |
| 239 | 239 |
| 240 /** | 240 /** |
| 241 * Returns the matching canonical route, or null if none matches. | 241 * Regular expression that captures the leading slash, the content and the |
| 242 * trailing slash in three different groups. |
| 243 * @const {!RegExp} |
| 244 */ |
| 245 var CANONICAL_PATH_REGEX = /(^\/)([\/-\w]+)(\/$)/; |
| 246 |
| 247 /** |
| 242 * @param {string} path | 248 * @param {string} path |
| 243 * @return {?settings.Route} | 249 * @return {?settings.Route} The matching canonical route, or null if none |
| 250 * matches. |
| 244 */ | 251 */ |
| 245 var getRouteForPath = function(path) { | 252 var getRouteForPath = function(path) { |
| 253 // Allow trailing slash in paths. |
| 254 var canonicalPath = path.replace(CANONICAL_PATH_REGEX, '$1$2'); |
| 255 |
| 246 // TODO(tommycli): Use Object.values once Closure compilation supports it. | 256 // TODO(tommycli): Use Object.values once Closure compilation supports it. |
| 247 var matchingKey = Object.keys(Route).find(function(key) { | 257 var matchingKey = Object.keys(Route).find(function(key) { |
| 248 return Route[key].path == path; | 258 return Route[key].path == canonicalPath; |
| 249 }); | 259 }); |
| 250 | 260 |
| 251 return Route[matchingKey] || null; | 261 return !!matchingKey ? Route[matchingKey] : null; |
| 252 }; | 262 }; |
| 253 | 263 |
| 254 /** | 264 /** |
| 255 * The current active route. This updated is only by settings.navigateTo or | 265 * The current active route. This updated is only by settings.navigateTo or |
| 256 * settings.initializeRouteFromUrl. | 266 * settings.initializeRouteFromUrl. |
| 257 * @private {!settings.Route} | 267 * @private {!settings.Route} |
| 258 */ | 268 */ |
| 259 var currentRoute_ = Route.BASIC; | 269 var currentRoute_ = Route.BASIC; |
| 260 | 270 |
| 261 /** | 271 /** |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 RouteObserverBehavior: RouteObserverBehavior, | 381 RouteObserverBehavior: RouteObserverBehavior, |
| 372 getRouteForPath: getRouteForPath, | 382 getRouteForPath: getRouteForPath, |
| 373 initializeRouteFromUrl: initializeRouteFromUrl, | 383 initializeRouteFromUrl: initializeRouteFromUrl, |
| 374 getCurrentRoute: getCurrentRoute, | 384 getCurrentRoute: getCurrentRoute, |
| 375 getQueryParameters: getQueryParameters, | 385 getQueryParameters: getQueryParameters, |
| 376 lastRouteChangeWasPopstate: lastRouteChangeWasPopstate, | 386 lastRouteChangeWasPopstate: lastRouteChangeWasPopstate, |
| 377 navigateTo: navigateTo, | 387 navigateTo: navigateTo, |
| 378 navigateToPreviousRoute: navigateToPreviousRoute, | 388 navigateToPreviousRoute: navigateToPreviousRoute, |
| 379 }; | 389 }; |
| 380 }); | 390 }); |
| OLD | NEW |