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-menu' shows a menu with a hardcoded set of pages and subpages. | 7 * 'settings-menu' shows a menu with a hardcoded set of pages and subpages. |
8 */ | 8 */ |
9 Polymer({ | 9 Polymer({ |
10 is: 'settings-menu', | 10 is: 'settings-menu', |
(...skipping 30 matching lines...) Expand all Loading... |
41 }.bind(this)); | 41 }.bind(this)); |
42 | 42 |
43 this.$.advancedPage.addEventListener('paper-submenu-open', function() { | 43 this.$.advancedPage.addEventListener('paper-submenu-open', function() { |
44 this.fire('toggle-advanced-page', true); | 44 this.fire('toggle-advanced-page', true); |
45 }.bind(this)); | 45 }.bind(this)); |
46 | 46 |
47 this.$.advancedPage.addEventListener('paper-submenu-close', function() { | 47 this.$.advancedPage.addEventListener('paper-submenu-close', function() { |
48 this.fire('toggle-advanced-page', false); | 48 this.fire('toggle-advanced-page', false); |
49 }.bind(this)); | 49 }.bind(this)); |
50 | 50 |
51 this.fire('toggle-advanced-page', this.currentRoute.page == 'advanced'); | 51 this.fire('toggle-advanced-page', |
| 52 settings.Route.ADVANCED.contains(this.currentRoute)); |
52 }, | 53 }, |
53 | 54 |
54 /** | 55 /** |
55 * @param {!settings.Route} newRoute | |
56 * @private | |
57 */ | |
58 currentRouteChanged_: function(newRoute) { | |
59 // Sync URL changes to the side nav menu. | |
60 | |
61 if (newRoute.page == 'advanced') { | |
62 assert(!this.pageVisibility || | |
63 this.pageVisibility.advancedSettings !== false); | |
64 this.$.advancedMenu.selected = this.currentRoute.section; | |
65 this.$.basicMenu.selected = null; | |
66 } else if (newRoute.page == 'basic') { | |
67 this.$.advancedMenu.selected = null; | |
68 this.$.basicMenu.selected = this.currentRoute.section; | |
69 } else { | |
70 this.$.advancedMenu.selected = null; | |
71 this.$.basicMenu.selected = null; | |
72 } | |
73 }, | |
74 | |
75 /** | |
76 * @param {!Node} target | 56 * @param {!Node} target |
77 * @private | 57 * @private |
78 */ | 58 */ |
79 ripple_: function(target) { | 59 ripple_: function(target) { |
80 var ripple = document.createElement('paper-ripple'); | 60 var ripple = document.createElement('paper-ripple'); |
81 ripple.addEventListener('transitionend', function() { | 61 ripple.addEventListener('transitionend', function() { |
82 ripple.remove(); | 62 ripple.remove(); |
83 }); | 63 }); |
84 target.appendChild(ripple); | 64 target.appendChild(ripple); |
85 ripple.downAction(); | 65 ripple.downAction(); |
86 ripple.upAction(); | 66 ripple.upAction(); |
87 }, | 67 }, |
88 | 68 |
89 /** | 69 /** |
90 * @param {!Event} event | 70 * @param {!Event} event |
91 * @private | 71 * @private |
92 */ | 72 */ |
93 openPage_: function(event) { | 73 openPage_: function(event) { |
94 this.ripple_(/** @type {!Node} */(event.currentTarget)); | 74 this.ripple_(/** @type {!Node} */(event.currentTarget)); |
95 var page = event.currentTarget.parentNode.dataset.page; | |
96 if (!page) | |
97 return; | |
98 | 75 |
99 var section = event.currentTarget.dataset.section; | 76 var route = settings.getRouteForPath(event.currentTarget.dataset.path); |
100 // TODO(tommycli): Use Object.values once Closure compilation supports it. | 77 assert(route, 'settings-menu has an an entry with an invalid path'); |
101 var matchingKey = Object.keys(settings.Route).find(function(key) { | 78 settings.navigateTo(route); |
102 var route = settings.Route[key]; | |
103 // TODO(tommycli): Remove usage of page, section, and subpage properties. | |
104 // Routes should be somehow directly bound to the menu elements. | |
105 return route.page == page && route.section == section && | |
106 route.subpage.length == 0; | |
107 }); | |
108 | |
109 if (matchingKey) | |
110 settings.navigateTo(settings.Route[matchingKey]); | |
111 }, | 79 }, |
112 | 80 |
113 /** | 81 /** |
114 * @param {boolean} opened Whether the menu is expanded. | 82 * @param {boolean} opened Whether the menu is expanded. |
115 * @return {string} Which icon to use. | 83 * @return {string} Which icon to use. |
116 * @private | 84 * @private |
117 * */ | 85 * */ |
118 arrowState_: function(opened) { | 86 arrowState_: function(opened) { |
119 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; | 87 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; |
120 }, | 88 }, |
121 }); | 89 }); |
OLD | NEW |