| 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-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 */ | 13 /** @private */ |
| 14 isAdvancedMenuOpen_: { | 14 isAdvancedMenuOpen_: { |
| 15 type: Boolean, | 15 type: Boolean, |
| 16 value: false, | 16 value: false, |
| 17 }, | 17 }, |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * Preferences state. | 20 * Preferences state. |
| 21 */ | 21 */ |
| 22 prefs: { | 22 prefs: { |
| 23 type: Object, | 23 type: Object, |
| 24 notify: true, | 24 notify: true, |
| 25 }, | 25 }, |
| 26 | 26 |
| 27 /** | 27 /** |
| 28 * The current active route. | 28 * The current active route. |
| 29 * @type {!SettingsRoute} | 29 * @type {!settings.Route} |
| 30 */ | 30 */ |
| 31 currentRoute: { | 31 currentRoute: { |
| 32 type: Object, | 32 type: Object, |
| 33 notify: true, | 33 notify: true, |
| 34 observer: 'currentRouteChanged_', | 34 observer: 'currentRouteChanged_', |
| 35 }, | 35 }, |
| 36 | 36 |
| 37 /** @private */ | 37 /** @private */ |
| 38 showAdvancedPage_: { | 38 showAdvancedPage_: { |
| 39 type: Boolean, | 39 type: Boolean, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 settings.getSearchManager().setCallback(function(isRunning) { | 77 settings.getSearchManager().setCallback(function(isRunning) { |
| 78 this.toolbarSpinnerActive = isRunning; | 78 this.toolbarSpinnerActive = isRunning; |
| 79 }.bind(this)); | 79 }.bind(this)); |
| 80 }, | 80 }, |
| 81 | 81 |
| 82 /** @override */ | 82 /** @override */ |
| 83 attached: function() { | 83 attached: function() { |
| 84 document.addEventListener('toggle-advanced-page', function(e) { | 84 document.addEventListener('toggle-advanced-page', function(e) { |
| 85 this.showAdvancedPage_ = e.detail; | 85 this.showAdvancedPage_ = e.detail; |
| 86 this.isAdvancedMenuOpen_ = e.detail; | 86 this.isAdvancedMenuOpen_ = e.detail; |
| 87 this.currentRoute = { | 87 settings.navigateTo(this.isAdvancedMenuOpen_ ? |
| 88 page: this.isAdvancedMenuOpen_ ? 'advanced' : 'basic', | 88 settings.Route.ADVANCED : settings.Route.BASIC); |
| 89 section: '', | |
| 90 subpage: [], | |
| 91 }; | |
| 92 if (this.showAdvancedPage_) { | 89 if (this.showAdvancedPage_) { |
| 93 doWhenReady( | 90 doWhenReady( |
| 94 function() { | 91 function() { |
| 95 var advancedPage = this.$$('settings-advanced-page'); | 92 var advancedPage = this.$$('settings-advanced-page'); |
| 96 return !!advancedPage && advancedPage.scrollHeight > 0; | 93 return !!advancedPage && advancedPage.scrollHeight > 0; |
| 97 }.bind(this), | 94 }.bind(this), |
| 98 function() { | 95 function() { |
| 99 this.$$('#toggleContainer').scrollIntoView(); | 96 this.$$('#toggleContainer').scrollIntoView(); |
| 100 }.bind(this)); | 97 }.bind(this)); |
| 101 } | 98 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 114 /** | 111 /** |
| 115 * @param {boolean} opened Whether the menu is expanded. | 112 * @param {boolean} opened Whether the menu is expanded. |
| 116 * @return {string} Which icon to use. | 113 * @return {string} Which icon to use. |
| 117 * @private | 114 * @private |
| 118 * */ | 115 * */ |
| 119 arrowState_: function(opened) { | 116 arrowState_: function(opened) { |
| 120 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; | 117 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; |
| 121 }, | 118 }, |
| 122 | 119 |
| 123 /** | 120 /** |
| 124 * @param {!SettingsRoute} newRoute | 121 * @param {!settings.Route} newRoute |
| 125 * @private | 122 * @private |
| 126 */ | 123 */ |
| 127 currentRouteChanged_: function(newRoute) { | 124 currentRouteChanged_: function(newRoute) { |
| 128 var isSubpage = !!newRoute.subpage.length; | 125 var isSubpage = !!newRoute.subpage.length; |
| 129 | 126 |
| 130 this.showAboutPage_ = newRoute.page == 'about'; | 127 this.showAboutPage_ = newRoute.page == 'about'; |
| 131 | 128 |
| 132 this.showAdvancedToggle_ = !this.showAboutPage_ && !isSubpage; | 129 this.showAdvancedToggle_ = !this.showAboutPage_ && !isSubpage; |
| 133 | 130 |
| 134 this.showBasicPage_ = this.showAdvancedToggle_ || newRoute.page == 'basic'; | 131 this.showBasicPage_ = this.showAdvancedToggle_ || newRoute.page == 'basic'; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 146 }, | 143 }, |
| 147 | 144 |
| 148 /** | 145 /** |
| 149 * Navigates to the default search page (if necessary). | 146 * Navigates to the default search page (if necessary). |
| 150 * @private | 147 * @private |
| 151 */ | 148 */ |
| 152 ensureInDefaultSearchPage_: function() { | 149 ensureInDefaultSearchPage_: function() { |
| 153 if (this.currentRoute.page != 'basic' || | 150 if (this.currentRoute.page != 'basic' || |
| 154 this.currentRoute.section != '' || | 151 this.currentRoute.section != '' || |
| 155 this.currentRoute.subpage.length != 0) { | 152 this.currentRoute.subpage.length != 0) { |
| 156 this.currentRoute = {page: 'basic', section: '', subpage: [], url: ''}; | 153 settings.navigateTo(settings.Route.BASIC); |
| 157 } | 154 } |
| 158 }, | 155 }, |
| 159 | 156 |
| 160 /** | 157 /** |
| 161 * @param {string} query | 158 * @param {string} query |
| 162 */ | 159 */ |
| 163 searchContents: function(query) { | 160 searchContents: function(query) { |
| 164 this.ensureInDefaultSearchPage_(); | 161 this.ensureInDefaultSearchPage_(); |
| 165 | 162 |
| 166 // Trigger rendering of the basic and advanced pages and search once ready. | 163 // Trigger rendering of the basic and advanced pages and search once ready. |
| 167 // Even if those are already rendered, yield to the message loop before | 164 // Even if those are already rendered, yield to the message loop before |
| 168 // initiating searching. | 165 // initiating searching. |
| 169 this.showBasicPage_ = true; | 166 this.showBasicPage_ = true; |
| 170 setTimeout(function() { | 167 setTimeout(function() { |
| 171 settings.getSearchManager().search( | 168 settings.getSearchManager().search( |
| 172 query, assert(this.$$('settings-basic-page'))); | 169 query, assert(this.$$('settings-basic-page'))); |
| 173 }.bind(this), 0); | 170 }.bind(this), 0); |
| 174 | 171 |
| 175 this.showAdvancedPage_ = true; | 172 this.showAdvancedPage_ = true; |
| 176 setTimeout(function() { | 173 setTimeout(function() { |
| 177 settings.getSearchManager().search( | 174 settings.getSearchManager().search( |
| 178 query, assert(this.$$('settings-advanced-page'))); | 175 query, assert(this.$$('settings-advanced-page'))); |
| 179 }.bind(this), 0); | 176 }.bind(this), 0); |
| 180 }, | 177 }, |
| 181 }); | 178 }); |
| OLD | NEW |