Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: chrome/browser/resources/settings/settings_menu/settings_menu.js

Issue 2184893002: Settings Router Refactor: Remove route.page legacy property. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@0217-settings-refactor-settings-menu
Patch Set: update test Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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',
(...skipping 30 matching lines...) Expand all
41 }.bind(this)); 41 }.bind(this));
42 42
43 this.$.advancedPage.addEventListener('paper-submenu-open', function() { 43 this.$.advancedPage.addEventListener('paper-submenu-open', function() {
44 this.fire('toggle-advanced-page', true); 44 this.fire('toggle-advanced-page', true);
45 }.bind(this)); 45 }.bind(this));
46 46
47 this.$.advancedPage.addEventListener('paper-submenu-close', function() { 47 this.$.advancedPage.addEventListener('paper-submenu-close', function() {
48 this.fire('toggle-advanced-page', false); 48 this.fire('toggle-advanced-page', false);
49 }.bind(this)); 49 }.bind(this));
50 50
51 this.fire('toggle-advanced-page', this.currentRoute.page == 'advanced'); 51 this.fire('toggle-advanced-page',
52 settings.Route.ADVANCED.contains(this.currentRoute));
52 }, 53 },
53 54
54 /** 55 /**
55 * @param {!settings.Route} newRoute 56 * @param {!settings.Route} newRoute
56 * @private 57 * @private
57 */ 58 */
58 currentRouteChanged_: function(newRoute) { 59 currentRouteChanged_: function(newRoute) {
59 // Sync URL changes to the side nav menu. 60 // Sync URL changes to the side nav menu.
60 61 this.$.advancedMenu.selected = this.currentRoute.path;
michaelpg 2016/07/29 20:28:53 if this works, can we just use (one-way) data bind
tommycli 2016/07/29 21:04:40 Done. Nice
michaelpg 2016/07/29 21:32:56 Awesome, we got rid of an entire currentRouteChang
61 if (newRoute.page == 'advanced') { 62 this.$.basicMenu.selected = this.currentRoute.path;
62 assert(!this.pageVisibility || 63 assert(!this.pageVisibility ||
63 this.pageVisibility.advancedSettings !== false); 64 this.pageVisibility.advancedSettings !== false);
64 this.$.advancedMenu.selected = this.currentRoute.section;
65 this.$.basicMenu.selected = null;
66 } else if (newRoute.page == 'basic') {
67 this.$.advancedMenu.selected = null;
68 this.$.basicMenu.selected = this.currentRoute.section;
69 } else {
70 this.$.advancedMenu.selected = null;
71 this.$.basicMenu.selected = null;
72 }
73 }, 65 },
74 66
75 /** 67 /**
76 * @param {!Node} target 68 * @param {!Node} target
77 * @private 69 * @private
78 */ 70 */
79 ripple_: function(target) { 71 ripple_: function(target) {
80 var ripple = document.createElement('paper-ripple'); 72 var ripple = document.createElement('paper-ripple');
81 ripple.addEventListener('transitionend', function() { 73 ripple.addEventListener('transitionend', function() {
82 ripple.remove(); 74 ripple.remove();
83 }); 75 });
84 target.appendChild(ripple); 76 target.appendChild(ripple);
85 ripple.downAction(); 77 ripple.downAction();
86 ripple.upAction(); 78 ripple.upAction();
87 }, 79 },
88 80
89 /** 81 /**
90 * @param {!Event} event 82 * @param {!Event} event
91 * @private 83 * @private
92 */ 84 */
93 openPage_: function(event) { 85 openPage_: function(event) {
94 this.ripple_(/** @type {!Node} */(event.currentTarget)); 86 this.ripple_(/** @type {!Node} */(event.currentTarget));
95 var page = event.currentTarget.parentNode.dataset.page;
96 if (!page)
97 return;
98 87
99 var section = event.currentTarget.dataset.section; 88 var route = settings.getRouteForPath(event.currentTarget.dataset.path);
michaelpg 2016/07/29 20:28:53 unfortunate that the menu has to do this -- settin
tommycli 2016/07/29 21:04:40 Yeah I know. Ideally I'd prefer to do settings.na
100 // TODO(tommycli): Use Object.values once Closure compilation supports it. 89 assert(route, 'settings-menu has an an entry with an invalid path');
101 var matchingKey = Object.keys(settings.Route).find(function(key) { 90 settings.navigateTo(route);
102 var route = settings.Route[key];
103 // TODO(tommycli): Remove usage of page, section, and subpage properties.
104 // Routes should be somehow directly bound to the menu elements.
105 return route.page == page && route.section == section &&
106 route.subpage.length == 0;
107 });
108
109 if (matchingKey)
110 settings.navigateTo(settings.Route[matchingKey]);
111 }, 91 },
112 92
113 /** 93 /**
114 * @param {boolean} opened Whether the menu is expanded. 94 * @param {boolean} opened Whether the menu is expanded.
115 * @return {string} Which icon to use. 95 * @return {string} Which icon to use.
116 * @private 96 * @private
117 * */ 97 * */
118 arrowState_: function(opened) { 98 arrowState_: function(opened) {
119 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; 99 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down';
120 }, 100 },
121 }); 101 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698