Chromium Code Reviews| 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 behaviors: [settings.RouteObserverBehavior], | |
| 13 | |
| 14 properties: { | 12 properties: { |
| 15 advancedOpened: { | 13 advancedOpened: { |
| 16 type: Boolean, | 14 type: Boolean, |
| 17 notify: true, | 15 notify: true, |
| 18 }, | 16 }, |
| 19 | 17 |
| 20 /** @private */ | |
| 21 aboutSelected_: Boolean, | |
| 22 | |
| 23 /** | 18 /** |
| 24 * Dictionary defining page visibility. | 19 * Dictionary defining page visibility. |
| 25 * @type {!GuestModePageVisibility} | 20 * @type {!GuestModePageVisibility} |
| 26 */ | 21 */ |
| 27 pageVisibility: { | 22 pageVisibility: { |
| 28 type: Object, | 23 type: Object, |
| 29 }, | 24 }, |
| 30 }, | 25 }, |
| 31 | 26 |
| 32 ready: function() { | 27 listeners: { |
| 33 // When a <paper-submenu> is created with the [opened] attribute as true, | 28 'topMenu.tap': 'onLinkTap_', |
| 34 // its _active member isn't correctly initialized. See this bug for more | 29 'subMenu.tap': 'onLinkTap_', |
| 35 // info: https://github.com/PolymerElements/paper-menu/issues/88. This means | 30 }, |
| 36 // the first tap to close an opened Advanced section does nothing (because | 31 |
| 37 // it calls .open() on an opened menu instead of .close(). This is a fix for | 32 /** @override */ |
| 38 // that bug without changing that code through its public API. | 33 attached: function() { |
| 39 // | 34 var currentRoute = settings.getCurrentRoute(); |
| 40 // TODO(dbeam): we're currently deciding whether <paper-{,sub}menu> are | 35 |
| 41 // right for our needs (there have been minor a11y problems). If we decide | 36 // Focus the initially selected path. |
| 42 // to keep <paper-{,sub}menu>, fix this bug with a local Chrome CL (ex: | 37 Array.prototype.forEach.call(this.root.querySelectorAll('a'), |
|
Dan Beam
2017/02/14 05:44:30
add this https://gist.github.com/danbeam/e17176126
hcarmona
2017/02/15 02:10:49
forEach -> for avoids closure weirdness.
| |
| 43 // https://codereview.chromium.org/2412343004) or a Polymer PR (ex: | 38 function(link) { |
| 44 // https://github.com/PolymerElements/paper-menu/pull/107). | 39 if (link.getAttribute('href') == currentRoute.path) |
| 45 if (this.advancedOpened) | 40 this.$.topMenu.selected = this.$.subMenu.selected = link.href; |
|
Dan Beam
2017/02/14 05:44:30
nit: why are you using .href here instead of getAt
hcarmona
2017/02/15 02:10:49
Done. Added a comment to explain why href is neede
| |
| 46 this.$.advancedSubmenu.open(); | 41 }.bind(this)); |
| 47 }, | 42 }, |
| 48 | 43 |
| 49 /** | 44 /** |
| 50 * @param {!settings.Route} newRoute | 45 * Prevent clicks on sidebar items from navigating. These are only links for |
| 46 * accessibility purposes, taps are handled separately by <iron-selector>. | |
| 47 * @param {!Event} event | |
| 48 * @private | |
| 51 */ | 49 */ |
| 52 currentRouteChanged: function(newRoute) { | 50 onLinkTap_: function(event) { |
| 53 // Make the three menus mutually exclusive. | 51 if (event.target.href) |
|
Dan Beam
2017/02/14 05:44:31
nit: this is probably fine but event.target.hasAtt
hcarmona
2017/02/15 02:10:49
Done.
| |
| 54 if (settings.Route.ABOUT.contains(newRoute)) { | 52 event.preventDefault(); |
| 55 this.aboutSelected_ = true; | |
| 56 this.$.advancedMenu.selected = null; | |
| 57 this.$.basicMenu.selected = null; | |
| 58 } else if (settings.Route.ADVANCED.contains(newRoute)) { | |
| 59 this.aboutSelected_ = false; | |
| 60 // For routes from URL entry, we need to set selected. | |
| 61 this.$.advancedMenu.selected = newRoute.path; | |
| 62 this.$.basicMenu.selected = null; | |
| 63 } else if (settings.Route.BASIC.contains(newRoute)) { | |
| 64 this.aboutSelected_ = false; | |
| 65 this.$.advancedMenu.selected = null; | |
| 66 // For routes from URL entry, we need to set selected. | |
| 67 this.$.basicMenu.selected = newRoute.path; | |
| 68 } | |
| 69 }, | 53 }, |
| 70 | 54 |
| 71 /** | 55 /** |
| 72 * @param {!Event} event | 56 * @param {!Event} event |
| 73 * @private | 57 * @private |
| 74 */ | 58 */ |
| 75 openPage_: function(event) { | 59 onSelectorActivate_: function(event) { |
| 76 var route = settings.getRouteForPath(event.currentTarget.dataset.path); | 60 // Keep both menus in sync. |
| 77 assert(route, 'settings-menu has an an entry with an invalid path'); | 61 this.$.topMenu.selected = this.$.subMenu.selected = event.detail.selected; |
| 62 | |
| 63 var path = new URL(event.detail.selected).pathname; | |
| 64 var route = settings.getRouteForPath(path); | |
| 65 assert(route, 'settings-menu has an entry with an invalid route.'); | |
| 78 settings.navigateTo( | 66 settings.navigateTo( |
| 79 route, /* dynamicParams */ null, /* removeSearch */ true); | 67 route, /* dynamicParams */ null, /* removeSearch */ true); |
| 80 }, | 68 }, |
| 81 | 69 |
| 82 /** | 70 /** |
| 83 * @param {boolean} opened Whether the menu is expanded. | 71 * @param {boolean} opened Whether the menu is expanded. |
| 84 * @return {string} Which icon to use. | 72 * @return {string} Which icon to use. |
| 85 * @private | 73 * @private |
| 86 * */ | 74 * */ |
| 87 arrowState_: function(opened) { | 75 arrowState_: function(opened) { |
| 88 return opened ? 'cr:arrow-drop-up' : 'cr:arrow-drop-down'; | 76 return opened ? 'cr:arrow-drop-up' : 'cr:arrow-drop-down'; |
| 89 }, | 77 }, |
| 90 }); | 78 }); |
| OLD | NEW |