| 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 * Example: | 9 * Example: |
| 10 * | 10 * |
| 11 * <settings-menu selected-page-id="{{selectedPageId}}"> | 11 * <settings-menu selected-page-id="{{selectedPageId}}"> |
| 12 * </settings-menu> | 12 * </settings-menu> |
| 13 */ | 13 */ |
| 14 Polymer({ | 14 Polymer({ |
| 15 is: 'settings-menu', | 15 is: 'settings-menu', |
| 16 | 16 |
| 17 properties: { | 17 properties: { |
| 18 /** | 18 /** |
| 19 * The current active route. | 19 * The current active route. |
| 20 * @type {!SettingsRoute} |
| 20 */ | 21 */ |
| 21 currentRoute: { | 22 currentRoute: { |
| 22 type: Object, | 23 type: Object, |
| 23 notify: true, | 24 notify: true, |
| 24 observer: 'currentRouteChanged_', | 25 observer: 'currentRouteChanged_', |
| 25 }, | 26 }, |
| 26 }, | 27 }, |
| 27 | 28 |
| 28 /** @private */ | 29 attached: function() { |
| 29 currentRouteChanged_: function() { | 30 document.addEventListener('toggle-advanced-page', function(e) { |
| 31 // Async to override Polymer trying to control |opened|. |
| 32 // To see issue, load into /settings/advanced and click the |
| 33 // 'Advanced' menu heading. |
| 34 this.async(function() { |
| 35 this.$.advancedPage.opened = e.detail; |
| 36 }.bind(this)); |
| 37 }.bind(this)); |
| 38 |
| 39 // Special case for initial load (via URL) into advanced settings. |
| 40 // Async to allow other listeners to attach. |
| 41 this.async(function() { |
| 42 this.fire('toggle-advanced-page', this.currentRoute.page == 'advanced'); |
| 43 }.bind(this)); |
| 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 /** |
| 81 * @param {!Event} event |
| 82 * @private |
| 83 */ |
| 84 toggleAdvancedPage_: function(event) { |
| 85 this.openPage_(event); |
| 86 this.fire('toggle-advanced-page', !this.$.advancedPage.opened); |
| 87 }, |
| 88 |
| 89 /** |
| 55 * @param {boolean} opened Whether the menu is expanded. | 90 * @param {boolean} opened Whether the menu is expanded. |
| 56 * @return {string} Which icon to use. | 91 * @return {string} Which icon to use. |
| 57 * @private | 92 * @private |
| 58 * */ | 93 * */ |
| 59 arrowState_: function(opened) { | 94 arrowState_: function(opened) { |
| 60 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; | 95 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; |
| 61 }, | 96 }, |
| 62 }); | 97 }); |
| OLD | NEW |