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 /** @override */ |
| 33 // When a <paper-submenu> is created with the [opened] attribute as true, | 28 attached: function() { |
| 34 // its _active member isn't correctly initialized. See this bug for more | 29 var currentRoute = settings.getCurrentRoute(); |
| 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 // Focus the initially selected path. |
| 37 // it calls .open() on an opened menu instead of .close(). This is a fix for | 32 Array.prototype.forEach.call(this.root.querySelectorAll('a'), |
|
Dan Beam
2017/02/13 20:04:07
doesn't NodeList already have a forEach?
hcarmona
2017/02/13 23:42:34
Closure didn't like forEach on the NodeList or a t
| |
| 38 // that bug without changing that code through its public API. | 33 function(link) { |
| 39 // | 34 var path = new URL(link.href).pathname; |
|
Dan Beam
2017/02/13 20:04:07
link.getAttribute('href') should not need to be ma
hcarmona
2017/02/13 23:42:34
Sweet! Updated.
| |
| 40 // TODO(dbeam): we're currently deciding whether <paper-{,sub}menu> are | 35 if (path == currentRoute.path) |
| 41 // right for our needs (there have been minor a11y problems). If we decide | 36 this.$.topMenu.selected = this.$.subMenu.selected = link.href; |
| 42 // to keep <paper-{,sub}menu>, fix this bug with a local Chrome CL (ex: | 37 }.bind(this)); |
| 43 // https://codereview.chromium.org/2412343004) or a Polymer PR (ex: | |
| 44 // https://github.com/PolymerElements/paper-menu/pull/107). | |
| 45 if (this.advancedOpened) | |
| 46 this.$.advancedSubmenu.open(); | |
| 47 }, | 38 }, |
| 48 | 39 |
| 49 /** | 40 /** |
| 50 * @param {!settings.Route} newRoute | 41 * Prevent clicks on sidebar items from navigating. These are only links for |
| 42 * accessibility purposes, taps are handled separately by <iron-selector>. | |
| 43 * @param {!Event} event | |
| 44 * @private | |
| 51 */ | 45 */ |
| 52 currentRouteChanged: function(newRoute) { | 46 onLinkTap_: function(event) { |
|
Dan Beam
2017/02/13 20:04:07
let's do this at a higher level, there's no reason
hcarmona
2017/02/13 23:42:34
Done.
| |
| 53 // Make the three menus mutually exclusive. | 47 event.preventDefault(); |
| 54 if (settings.Route.ABOUT.contains(newRoute)) { | |
| 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 }, | 48 }, |
| 70 | 49 |
| 71 /** | 50 /** |
| 72 * @param {!Event} event | 51 * @param {!Event} event |
| 73 * @private | 52 * @private |
| 74 */ | 53 */ |
| 75 openPage_: function(event) { | 54 onSelectorActivate_: function(event) { |
| 76 var route = settings.getRouteForPath(event.currentTarget.dataset.path); | 55 // Keep both menus in sync. |
| 77 assert(route, 'settings-menu has an an entry with an invalid path'); | 56 this.$.topMenu.selected = this.$.subMenu.selected = event.detail.selected; |
| 57 | |
| 58 var path = new URL(event.detail.selected).pathname; | |
| 59 var route = settings.getRouteForPath(path); | |
| 60 assert(route, 'settings-menu has an entry with an invalid route.'); | |
| 78 settings.navigateTo( | 61 settings.navigateTo( |
| 79 route, /* dynamicParams */ null, /* removeSearch */ true); | 62 route, /* dynamicParams */ null, /* removeSearch */ true); |
| 80 }, | 63 }, |
| 81 | 64 |
| 82 /** | 65 /** |
| 83 * @param {boolean} opened Whether the menu is expanded. | 66 * @param {boolean} opened Whether the menu is expanded. |
| 84 * @return {string} Which icon to use. | 67 * @return {string} Which icon to use. |
| 85 * @private | 68 * @private |
| 86 * */ | 69 * */ |
| 87 arrowState_: function(opened) { | 70 arrowState_: function(opened) { |
| 88 return opened ? 'cr:arrow-drop-up' : 'cr:arrow-drop-down'; | 71 return opened ? 'cr:arrow-drop-up' : 'cr:arrow-drop-down'; |
| 89 }, | 72 }, |
| 90 }); | 73 }); |
| OLD | NEW |