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

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

Issue 2160713002: MD Settings: refactor some main page properties, fix Advanced toggle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 5 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
« no previous file with comments | « chrome/browser/resources/settings/settings_main/settings_main.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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-main' displays the selected settings page. 7 * 'settings-main' displays the selected settings page.
8 */ 8 */
9 Polymer({ 9 Polymer({
10 is: 'settings-main', 10 is: 'settings-main',
11 11
12 properties: { 12 properties: {
13 /** @private */
14 isAdvancedMenuOpen_: {
15 type: Boolean,
16 value: false,
17 },
18
19 /** 13 /**
20 * Preferences state. 14 * Preferences state.
21 */ 15 */
22 prefs: { 16 prefs: {
23 type: Object, 17 type: Object,
24 notify: true, 18 notify: true,
25 }, 19 },
26 20
27 /** 21 /**
28 * The current active route. 22 * The current active route.
29 * @type {!SettingsRoute} 23 * @type {!SettingsRoute}
30 */ 24 */
31 currentRoute: { 25 currentRoute: {
32 type: Object, 26 type: Object,
33 notify: true, 27 notify: true,
34 observer: 'currentRouteChanged_', 28 observer: 'currentRouteChanged_',
35 }, 29 },
36 30
37 /** @private */ 31 /** @private */
38 showAdvancedPage_: { 32 advancedToggleExpanded_: {
39 type: Boolean, 33 type: Boolean,
40 value: false, 34 value: false,
41 }, 35 },
42 36
43 /** @private */ 37 /** @private */
44 showAdvancedToggle_: { 38 inSubpage_: Boolean,
45 type: Boolean,
46 value: true,
47 },
48 39
49 /** @private */ 40 /** @private */
50 showBasicPage_: { 41 showAboutPage_: Boolean,
51 type: Boolean,
52 value: true,
53 },
54 42
55 /** @private */ 43 /** @private */
56 showAboutPage_: { 44 showBasicPage_: Boolean,
57 type: Boolean, 45
58 value: false, 46 /** @private */
59 }, 47 showAdvancedPage_: Boolean,
60 48
61 toolbarSpinnerActive: { 49 toolbarSpinnerActive: {
62 type: Boolean, 50 type: Boolean,
63 value: false, 51 value: false,
64 notify: true, 52 notify: true,
65 }, 53 },
66 }, 54 },
67 55
68 /** @override */ 56 /** @override */
69 created: function() { 57 created: function() {
70 /** @private {!PromiseResolver} */ 58 /** @private {!PromiseResolver} */
71 this.resolver_ = new PromiseResolver; 59 this.resolver_ = new PromiseResolver;
72 settings.main.rendered = this.resolver_.promise; 60 settings.main.rendered = this.resolver_.promise;
73 }, 61 },
74 62
75 /** @override */ 63 /** @override */
76 ready: function() { 64 ready: function() {
77 settings.getSearchManager().setCallback(function(isRunning) { 65 settings.getSearchManager().setCallback(function(isRunning) {
78 this.toolbarSpinnerActive = isRunning; 66 this.toolbarSpinnerActive = isRunning;
79 }.bind(this)); 67 }.bind(this));
80 }, 68 },
81 69
82 /** @override */ 70 /** @override */
83 attached: function() { 71 attached: function() {
84 document.addEventListener('toggle-advanced-page', function(e) { 72 document.addEventListener('toggle-advanced-page', function(e) {
85 this.showAdvancedPage_ = e.detail; 73 this.advancedToggleExpanded_ = e.detail;
86 this.isAdvancedMenuOpen_ = e.detail;
87 this.currentRoute = { 74 this.currentRoute = {
88 page: this.isAdvancedMenuOpen_ ? 'advanced' : 'basic', 75 page: this.advancedToggleExpanded_ ? 'advanced' : 'basic',
89 section: '', 76 section: '',
90 subpage: [], 77 subpage: [],
91 }; 78 };
92 if (this.showAdvancedPage_) { 79 if (this.advancedToggleExpanded_) {
93 doWhenReady( 80 doWhenReady(
94 function() { 81 function() {
95 var advancedPage = this.$$('settings-advanced-page'); 82 var advancedPage = this.$$('settings-advanced-page');
96 return !!advancedPage && advancedPage.scrollHeight > 0; 83 return !!advancedPage && advancedPage.scrollHeight > 0;
97 }.bind(this), 84 }.bind(this),
98 function() { 85 function() {
99 this.$$('#toggleContainer').scrollIntoView(); 86 this.$$('#toggleContainer').scrollIntoView();
100 }.bind(this)); 87 }.bind(this));
101 } 88 }
102 }.bind(this)); 89 }.bind(this));
103 90
104 doWhenReady( 91 doWhenReady(
105 function() { 92 function() {
106 var basicPage = this.$$('settings-basic-page'); 93 var basicPage = this.$$('settings-basic-page');
107 return !!basicPage && basicPage.scrollHeight > 0; 94 return !!basicPage && basicPage.scrollHeight > 0;
108 }.bind(this), 95 }.bind(this),
109 function() { 96 function() {
110 this.resolver_.resolve(); 97 this.resolver_.resolve();
111 }.bind(this)); 98 }.bind(this));
112 }, 99 },
113 100
114 /** 101 /**
115 * @param {boolean} opened Whether the menu is expanded. 102 * @param {boolean} opened Whether the menu is expanded.
116 * @return {string} Which icon to use. 103 * @return {string} Which icon to use.
117 * @private 104 * @private
118 * */ 105 */
119 arrowState_: function(opened) { 106 arrowState_: function(opened) {
120 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; 107 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down';
121 }, 108 },
122 109
123 /** 110 /**
124 * @param {!SettingsRoute} newRoute 111 * @param {!SettingsRoute} newRoute
125 * @private 112 * @private
126 */ 113 */
127 currentRouteChanged_: function(newRoute) { 114 currentRouteChanged_: function(newRoute) {
128 var isSubpage = !!newRoute.subpage.length; 115 this.inSubpage_ = newRoute.subpage.length > 0;
116 this.showAboutPage_ = newRoute.page == 'about';
dpapad 2016/07/20 21:30:08 Drive-by question: Would it make more sense to pac
michaelpg 2016/07/20 22:25:39 Fine idea, done.
117 if (this.showAboutPage_) {
118 this.showBasicPage_ = this.showAdvancedPage_ = false;
119 } else if (newRoute.page == 'basic') {
120 this.showBasicPage_ = true;
121 this.showAdvancedPage_ = !this.inSubpage_ && this.advancedToggleExpanded_;
122 } else if (newRoute.page == 'advanced') {
123 this.showBasicPage_ = !this.inSubpage_;
124 this.showAdvancedPage_ = this.advancedToggleExpanded_ = true;
125 } else {
126 assertNotReached('Invalid page ' + newRoute.page);
127 }
129 128
130 this.showAboutPage_ = newRoute.page == 'about'; 129 this.style.height = this.inSubpage_ ? '100%' : '';
131
132 this.showAdvancedToggle_ = !this.showAboutPage_ && !isSubpage;
133
134 this.showBasicPage_ = this.showAdvancedToggle_ || newRoute.page == 'basic';
135
136 this.showAdvancedPage_ =
137 (this.isAdvancedMenuOpen_ && this.showAdvancedToggle_) ||
138 newRoute.page == 'advanced';
139
140 this.style.height = isSubpage ? '100%' : '';
141 }, 130 },
142 131
143 /** @private */ 132 /** @private */
144 toggleAdvancedPage_: function() { 133 toggleAdvancedPage_: function() {
145 this.fire('toggle-advanced-page', !this.isAdvancedMenuOpen_); 134 this.fire('toggle-advanced-page', !this.advancedToggleExpanded_);
146 }, 135 },
147 136
148 /** 137 /**
149 * Navigates to the default search page (if necessary). 138 * Navigates to the default search page (if necessary).
150 * @private 139 * @private
151 */ 140 */
152 ensureInDefaultSearchPage_: function() { 141 ensureInDefaultSearchPage_: function() {
153 if (this.currentRoute.page != 'basic' || 142 if (this.currentRoute.page != 'basic' ||
154 this.currentRoute.section != '' || 143 this.currentRoute.section != '' ||
155 this.currentRoute.subpage.length != 0) { 144 this.currentRoute.subpage.length != 0) {
(...skipping 16 matching lines...) Expand all
172 query, assert(this.$$('settings-basic-page'))); 161 query, assert(this.$$('settings-basic-page')));
173 }.bind(this), 0); 162 }.bind(this), 0);
174 163
175 this.showAdvancedPage_ = true; 164 this.showAdvancedPage_ = true;
176 setTimeout(function() { 165 setTimeout(function() {
177 settings.getSearchManager().search( 166 settings.getSearchManager().search(
178 query, assert(this.$$('settings-advanced-page'))); 167 query, assert(this.$$('settings-advanced-page')));
179 }.bind(this), 0); 168 }.bind(this), 0);
180 }, 169 },
181 }); 170 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/settings/settings_main/settings_main.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698