| 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 * | |
| 9 * Example: | |
| 10 * | |
| 11 * <settings-menu selected-page-id="{{selectedPageId}}"> | |
| 12 * </settings-menu> | |
| 13 */ | 8 */ |
| 14 Polymer({ | 9 Polymer({ |
| 15 is: 'settings-menu', | 10 is: 'settings-menu', |
| 16 | 11 |
| 17 properties: { | 12 properties: { |
| 13 /** @private */ |
| 14 advancedOpened_: Boolean, |
| 15 |
| 18 /** | 16 /** |
| 19 * The current active route. | 17 * The current active route. |
| 18 * @type {!SettingsRoute} |
| 20 */ | 19 */ |
| 21 currentRoute: { | 20 currentRoute: { |
| 22 type: Object, | 21 type: Object, |
| 23 notify: true, | 22 notify: true, |
| 24 observer: 'currentRouteChanged_', | 23 observer: 'currentRouteChanged_', |
| 25 }, | 24 }, |
| 26 }, | 25 }, |
| 27 | 26 |
| 28 /** @private */ | 27 attached: function() { |
| 29 currentRouteChanged_: function() { | 28 document.addEventListener('toggle-advanced-page', function(e) { |
| 29 if (e.detail) |
| 30 this.$.advancedPage.open(); |
| 31 else |
| 32 this.$.advancedPage.close(); |
| 33 }.bind(this)); |
| 34 |
| 35 this.$.advancedPage.addEventListener('paper-submenu-open', function() { |
| 36 this.fire('toggle-advanced-page', true); |
| 37 }.bind(this)); |
| 38 |
| 39 this.$.advancedPage.addEventListener('paper-submenu-close', function() { |
| 40 this.fire('toggle-advanced-page', false); |
| 41 }.bind(this)); |
| 42 |
| 43 this.fire('toggle-advanced-page', this.currentRoute.page == 'advanced'); |
| 44 }, |
| 45 |
| 46 /** |
| 47 * @param {!SettingsRoute} newRoute |
| 48 * @private |
| 49 */ |
| 50 currentRouteChanged_: function(newRoute) { |
| 30 // Sync URL changes to the side nav menu. | 51 // Sync URL changes to the side nav menu. |
| 31 | 52 |
| 32 this.$.advancedPage.opened = this.currentRoute.page == 'advanced'; | 53 if (newRoute.page == 'advanced') { |
| 33 this.$.basicPage.opened = this.currentRoute.page == 'basic'; | |
| 34 | |
| 35 if (this.$.advancedPage.opened) | |
| 36 this.$.advancedMenu.selected = this.currentRoute.section; | 54 this.$.advancedMenu.selected = this.currentRoute.section; |
| 37 | 55 this.$.basicMenu.selected = null; |
| 38 if (this.$.basicPage.opened) | 56 } else if (newRoute.page == 'basic') { |
| 57 this.$.advancedMenu.selected = null; |
| 39 this.$.basicMenu.selected = this.currentRoute.section; | 58 this.$.basicMenu.selected = this.currentRoute.section; |
| 59 } else { |
| 60 this.$.advancedMenu.selected = null; |
| 61 this.$.basicMenu.selected = null; |
| 62 } |
| 40 }, | 63 }, |
| 41 | 64 |
| 42 /** @private */ | 65 /** |
| 66 * @param {!Event} event |
| 67 * @private |
| 68 */ |
| 43 openPage_: function(event) { | 69 openPage_: function(event) { |
| 44 var submenuRoute = event.currentTarget.parentNode.dataset.page; | 70 var submenuRoute = event.currentTarget.parentNode.dataset.page; |
| 45 if (submenuRoute) { | 71 if (submenuRoute) { |
| 46 this.currentRoute = { | 72 this.currentRoute = { |
| 47 page: submenuRoute, | 73 page: submenuRoute, |
| 48 section: event.currentTarget.dataset.section, | 74 section: event.currentTarget.dataset.section, |
| 49 subpage: [], | 75 subpage: [], |
| 50 }; | 76 }; |
| 51 } | 77 } |
| 52 }, | 78 }, |
| 53 | 79 |
| 54 /** | 80 /** |
| 55 * @param {boolean} opened Whether the menu is expanded. | 81 * @param {boolean} opened Whether the menu is expanded. |
| 56 * @return {string} Which icon to use. | 82 * @return {string} Which icon to use. |
| 57 * @private | 83 * @private |
| 58 * */ | 84 * */ |
| 59 arrowState_: function(opened) { | 85 arrowState_: function(opened) { |
| 60 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; | 86 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; |
| 61 }, | 87 }, |
| 62 }); | 88 }); |
| OLD | NEW |