OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 /** | 5 /** |
6 * @fileoverview | 6 * @fileoverview |
7 * 'settings-router' is a simple router for settings. Its responsibilities: | 7 * 'settings-router' is a simple router for settings. Its responsibilities: |
8 * - Update the URL when the routing state changes. | 8 * - Update the URL when the routing state changes. |
9 * - Initialize the routing state with the initial URL. | 9 * - Initialize the routing state with the initial URL. |
10 * - Process and validate all routing state changes. | 10 * - Process and validate all routing state changes. |
11 * | 11 * |
12 * Example: | 12 * Example: |
13 * | 13 * |
14 * <settings-router current-route="{{currentRoute}}"> | 14 * <settings-router current-route="{{currentRoute}}"> |
15 * </settings-router> | 15 * </settings-router> |
16 */ | 16 */ |
17 Polymer({ | 17 Polymer({ |
18 is: 'settings-router', | 18 is: 'settings-router', |
19 | 19 |
20 properties: { | 20 properties: { |
21 /** | 21 /** |
22 * The current active route. This may only be updated via the global | 22 * The current active route. This may only be updated via the global |
23 * function settings.navigateTo. | 23 * function settings.navigateTo. |
24 * | 24 * |
25 * currentRoute.page refers to top-level pages such as Basic and Advanced. | |
26 * | |
27 * currentRoute.section is only non-empty when the user is on a subpage. If | 25 * currentRoute.section is only non-empty when the user is on a subpage. If |
28 * the user is on Basic, for instance, this is an empty string. | 26 * the user is on Basic, for instance, this is an empty string. |
29 * | 27 * |
30 * currentRoute.subpage is an Array. The last element is the actual subpage | 28 * currentRoute.subpage is an Array. The last element is the actual subpage |
31 * the user is on. The previous elements are the ancestor subpages. This | 29 * the user is on. The previous elements are the ancestor subpages. This |
32 * enables support for multiple paths to the same subpage. This is used by | 30 * enables support for multiple paths to the same subpage. This is used by |
33 * both the Back button and the Breadcrumb to determine ancestor subpages. | 31 * both the Back button and the Breadcrumb to determine ancestor subpages. |
34 * @type {!settings.Route} | 32 * @type {!settings.Route} |
35 */ | 33 */ |
36 currentRoute: { | 34 currentRoute: { |
(...skipping 29 matching lines...) Expand all Loading... |
66 navigateTo_: function(route) { | 64 navigateTo_: function(route) { |
67 assert(!!route); | 65 assert(!!route); |
68 | 66 |
69 if (route == this.currentRoute) | 67 if (route == this.currentRoute) |
70 return; | 68 return; |
71 | 69 |
72 window.history.pushState(undefined, document.title, route.path); | 70 window.history.pushState(undefined, document.title, route.path); |
73 this.currentRoute = route; | 71 this.currentRoute = route; |
74 }, | 72 }, |
75 }); | 73 }); |
OLD | NEW |