| 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', |
| 11 | 11 |
| 12 properties: { | 12 properties: { |
| 13 /** @private */ | 13 /** @private */ |
| 14 advancedOpened_: Boolean, | 14 advancedOpened_: Boolean, |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * The current active route. | 17 * The current active route. |
| 18 * @type {!SettingsRoute} | 18 * @type {!settings.Route} |
| 19 */ | 19 */ |
| 20 currentRoute: { | 20 currentRoute: { |
| 21 type: Object, | 21 type: Object, |
| 22 notify: true, | 22 notify: true, |
| 23 observer: 'currentRouteChanged_', | 23 observer: 'currentRouteChanged_', |
| 24 }, | 24 }, |
| 25 | 25 |
| 26 /** | 26 /** |
| 27 * Dictionary defining page visibility. | 27 * Dictionary defining page visibility. |
| 28 * @type {!GuestModePageVisibility} | 28 * @type {!GuestModePageVisibility} |
| (...skipping 16 matching lines...) Expand all Loading... |
| 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', this.currentRoute.page == 'advanced'); |
| 52 }, | 52 }, |
| 53 | 53 |
| 54 /** | 54 /** |
| 55 * @param {!SettingsRoute} newRoute | 55 * @param {!settings.Route} newRoute |
| 56 * @private | 56 * @private |
| 57 */ | 57 */ |
| 58 currentRouteChanged_: function(newRoute) { | 58 currentRouteChanged_: function(newRoute) { |
| 59 // Sync URL changes to the side nav menu. | 59 // Sync URL changes to the side nav menu. |
| 60 | 60 |
| 61 if (newRoute.page == 'advanced') { | 61 if (newRoute.page == 'advanced') { |
| 62 assert(!this.pageVisibility || | 62 assert(!this.pageVisibility || |
| 63 this.pageVisibility.advancedSettings !== false); | 63 this.pageVisibility.advancedSettings !== false); |
| 64 this.$.advancedMenu.selected = this.currentRoute.section; | 64 this.$.advancedMenu.selected = this.currentRoute.section; |
| 65 this.$.basicMenu.selected = null; | 65 this.$.basicMenu.selected = null; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 85 ripple.downAction(); | 85 ripple.downAction(); |
| 86 ripple.upAction(); | 86 ripple.upAction(); |
| 87 }, | 87 }, |
| 88 | 88 |
| 89 /** | 89 /** |
| 90 * @param {!Event} event | 90 * @param {!Event} event |
| 91 * @private | 91 * @private |
| 92 */ | 92 */ |
| 93 openPage_: function(event) { | 93 openPage_: function(event) { |
| 94 this.ripple_(/** @type {!Node} */(event.currentTarget)); | 94 this.ripple_(/** @type {!Node} */(event.currentTarget)); |
| 95 var submenuRoute = event.currentTarget.parentNode.dataset.page; | 95 var page = event.currentTarget.parentNode.dataset.page; |
| 96 if (submenuRoute) { | 96 if (!page) |
| 97 this.currentRoute = { | 97 return; |
| 98 page: submenuRoute, | 98 |
| 99 section: event.currentTarget.dataset.section, | 99 var section = event.currentTarget.dataset.section; |
| 100 subpage: [], | 100 // TODO(tommycli): Use Object.values once Closure compilation supports it. |
| 101 }; | 101 var matchingKey = Object.keys(settings.Route).find(function(key) { |
| 102 } | 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]); |
| 103 }, | 111 }, |
| 104 | 112 |
| 105 /** | 113 /** |
| 106 * @param {boolean} opened Whether the menu is expanded. | 114 * @param {boolean} opened Whether the menu is expanded. |
| 107 * @return {string} Which icon to use. | 115 * @return {string} Which icon to use. |
| 108 * @private | 116 * @private |
| 109 * */ | 117 * */ |
| 110 arrowState_: function(opened) { | 118 arrowState_: function(opened) { |
| 111 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; | 119 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; |
| 112 }, | 120 }, |
| 113 }); | 121 }); |
| OLD | NEW |