| 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: { |
| 18 /** | 13 /** |
| 19 * The current active route. | 14 * The current active route. |
| 15 * @type {!SettingsRoute} |
| 20 */ | 16 */ |
| 21 currentRoute: { | 17 currentRoute: { |
| 22 type: Object, | 18 type: Object, |
| 23 notify: true, | 19 notify: true, |
| 24 observer: 'currentRouteChanged_', | 20 observer: 'currentRouteChanged_', |
| 25 }, | 21 }, |
| 26 }, | 22 }, |
| 27 | 23 |
| 28 /** @private */ | 24 attached: function() { |
| 29 currentRouteChanged_: function() { | 25 document.addEventListener('toggle-advanced-page', function(e) { |
| 26 // Async to override Polymer trying to control |opened|. |
| 27 // To see issue, load into /settings/advanced and click the |
| 28 // 'Advanced' menu heading. |
| 29 this.async(function() { |
| 30 this.$.advancedPage.opened = e.detail; |
| 31 }.bind(this)); |
| 32 }.bind(this)); |
| 33 |
| 34 // Special case for initial load (via URL) into advanced settings. |
| 35 // Async to allow other listeners to attach. |
| 36 this.async(function() { |
| 37 this.fire('toggle-advanced-page', this.currentRoute.page == 'advanced'); |
| 38 }.bind(this)); |
| 39 }, |
| 40 |
| 41 /** |
| 42 * @param {!SettingsRoute} newRoute |
| 43 * @private |
| 44 */ |
| 45 currentRouteChanged_: function(newRoute) { |
| 30 // Sync URL changes to the side nav menu. | 46 // Sync URL changes to the side nav menu. |
| 31 | 47 |
| 32 this.$.advancedPage.opened = this.currentRoute.page == 'advanced'; | 48 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; | 49 this.$.advancedMenu.selected = this.currentRoute.section; |
| 37 | 50 this.$.basicMenu.selected = null; |
| 38 if (this.$.basicPage.opened) | 51 } else if (newRoute.page == 'basic') { |
| 52 this.$.advancedMenu.selected = null; |
| 39 this.$.basicMenu.selected = this.currentRoute.section; | 53 this.$.basicMenu.selected = this.currentRoute.section; |
| 54 } else { |
| 55 this.$.advancedMenu.selected = null; |
| 56 this.$.basicMenu.selected = null; |
| 57 } |
| 40 }, | 58 }, |
| 41 | 59 |
| 42 /** @private */ | 60 /** |
| 61 * @param {!Event} event |
| 62 * @private |
| 63 */ |
| 43 openPage_: function(event) { | 64 openPage_: function(event) { |
| 44 var submenuRoute = event.currentTarget.parentNode.dataset.page; | 65 var submenuRoute = event.currentTarget.parentNode.dataset.page; |
| 45 if (submenuRoute) { | 66 if (submenuRoute) { |
| 46 this.currentRoute = { | 67 this.currentRoute = { |
| 47 page: submenuRoute, | 68 page: submenuRoute, |
| 48 section: event.currentTarget.dataset.section, | 69 section: event.currentTarget.dataset.section, |
| 49 subpage: [], | 70 subpage: [], |
| 50 }; | 71 }; |
| 51 } | 72 } |
| 52 }, | 73 }, |
| 53 | 74 |
| 54 /** | 75 /** |
| 76 * @param {!Event} event |
| 77 * @private |
| 78 */ |
| 79 toggleAdvancedPage_: function(event) { |
| 80 this.openPage_(event); |
| 81 this.fire('toggle-advanced-page', !this.$.advancedPage.opened); |
| 82 }, |
| 83 |
| 84 /** |
| 55 * @param {boolean} opened Whether the menu is expanded. | 85 * @param {boolean} opened Whether the menu is expanded. |
| 56 * @return {string} Which icon to use. | 86 * @return {string} Which icon to use. |
| 57 * @private | 87 * @private |
| 58 * */ | 88 * */ |
| 59 arrowState_: function(opened) { | 89 arrowState_: function(opened) { |
| 60 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; | 90 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; |
| 61 }, | 91 }, |
| 62 }); | 92 }); |
| OLD | NEW |