| 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 /** | 13 /** |
| 14 * Preferences state. | 14 * Preferences state. |
| 15 */ | 15 */ |
| 16 prefs: { | 16 prefs: { |
| 17 type: Object, | 17 type: Object, |
| 18 notify: true, | 18 notify: true, |
| 19 }, | 19 }, |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * The current active route. | 22 * The current active route. |
| 23 * @type {!SettingsRoute} | 23 * @type {!settings.Route} |
| 24 */ | 24 */ |
| 25 currentRoute: { | 25 currentRoute: { |
| 26 type: Object, | 26 type: Object, |
| 27 notify: true, | 27 notify: true, |
| 28 observer: 'currentRouteChanged_', | 28 observer: 'currentRouteChanged_', |
| 29 }, | 29 }, |
| 30 | 30 |
| 31 /** @private */ | 31 /** @private */ |
| 32 advancedToggleExpanded_: { | 32 advancedToggleExpanded_: { |
| 33 type: Boolean, | 33 type: Boolean, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 ready: function() { | 67 ready: function() { |
| 68 settings.getSearchManager().setCallback(function(isRunning) { | 68 settings.getSearchManager().setCallback(function(isRunning) { |
| 69 this.toolbarSpinnerActive = isRunning; | 69 this.toolbarSpinnerActive = isRunning; |
| 70 }.bind(this)); | 70 }.bind(this)); |
| 71 }, | 71 }, |
| 72 | 72 |
| 73 /** @override */ | 73 /** @override */ |
| 74 attached: function() { | 74 attached: function() { |
| 75 document.addEventListener('toggle-advanced-page', function(e) { | 75 document.addEventListener('toggle-advanced-page', function(e) { |
| 76 this.advancedToggleExpanded_ = e.detail; | 76 this.advancedToggleExpanded_ = e.detail; |
| 77 this.currentRoute = { | 77 settings.navigateTo(this.advancedToggleExpanded_ ? |
| 78 page: this.advancedToggleExpanded_ ? 'advanced' : 'basic', | 78 settings.Route.ADVANCED : settings.Route.BASIC); |
| 79 section: '', | |
| 80 subpage: [], | |
| 81 }; | |
| 82 }.bind(this)); | 79 }.bind(this)); |
| 83 | 80 |
| 84 doWhenReady( | 81 doWhenReady( |
| 85 function() { | 82 function() { |
| 86 var basicPage = this.$$('settings-basic-page'); | 83 var basicPage = this.$$('settings-basic-page'); |
| 87 return !!basicPage && basicPage.scrollHeight > 0; | 84 return !!basicPage && basicPage.scrollHeight > 0; |
| 88 }.bind(this), | 85 }.bind(this), |
| 89 function() { | 86 function() { |
| 90 this.resolver_.resolve(); | 87 this.resolver_.resolve(); |
| 91 }.bind(this)); | 88 }.bind(this)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 103 /** | 100 /** |
| 104 * @param {boolean} showBasicPage | 101 * @param {boolean} showBasicPage |
| 105 * @param {boolean} inSubpage | 102 * @param {boolean} inSubpage |
| 106 * @return {boolean} | 103 * @return {boolean} |
| 107 */ | 104 */ |
| 108 showAdvancedToggle_: function(showBasicPage, inSubpage) { | 105 showAdvancedToggle_: function(showBasicPage, inSubpage) { |
| 109 return showBasicPage && !inSubpage; | 106 return showBasicPage && !inSubpage; |
| 110 }, | 107 }, |
| 111 | 108 |
| 112 /** | 109 /** |
| 113 * @param {!SettingsRoute} newRoute | |
| 114 * @private | 110 * @private |
| 115 */ | 111 */ |
| 116 currentRouteChanged_: function(newRoute) { | 112 currentRouteChanged_: function(newRoute) { |
| 117 this.inSubpage_ = newRoute.subpage.length > 0; | 113 this.inSubpage_ = newRoute.subpage.length > 0; |
| 118 this.style.height = this.inSubpage_ ? '100%' : ''; | 114 this.style.height = this.inSubpage_ ? '100%' : ''; |
| 119 | 115 |
| 120 if (newRoute.page == 'about') { | 116 if (newRoute.page == 'about') { |
| 121 this.showPages_ = {about: true, basic: false, advanced: false}; | 117 this.showPages_ = {about: true, basic: false, advanced: false}; |
| 122 } else { | 118 } else { |
| 123 this.showPages_ = { | 119 this.showPages_ = { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 135 /** @private */ | 131 /** @private */ |
| 136 toggleAdvancedPage_: function() { | 132 toggleAdvancedPage_: function() { |
| 137 this.fire('toggle-advanced-page', !this.advancedToggleExpanded_); | 133 this.fire('toggle-advanced-page', !this.advancedToggleExpanded_); |
| 138 }, | 134 }, |
| 139 | 135 |
| 140 /** | 136 /** |
| 141 * Navigates to the default search page (if necessary). | 137 * Navigates to the default search page (if necessary). |
| 142 * @private | 138 * @private |
| 143 */ | 139 */ |
| 144 ensureInDefaultSearchPage_: function() { | 140 ensureInDefaultSearchPage_: function() { |
| 145 if (this.currentRoute.page != 'basic' || | 141 settings.navigateTo(settings.Route.BASIC); |
| 146 this.currentRoute.section != '' || | |
| 147 this.currentRoute.subpage.length != 0) { | |
| 148 this.currentRoute = {page: 'basic', section: '', subpage: [], url: ''}; | |
| 149 } | |
| 150 }, | 142 }, |
| 151 | 143 |
| 152 /** | 144 /** |
| 153 * @param {string} query | 145 * @param {string} query |
| 154 */ | 146 */ |
| 155 searchContents: function(query) { | 147 searchContents: function(query) { |
| 156 this.ensureInDefaultSearchPage_(); | 148 this.ensureInDefaultSearchPage_(); |
| 157 | 149 |
| 158 // Trigger rendering of the basic and advanced pages and search once ready. | 150 // Trigger rendering of the basic and advanced pages and search once ready. |
| 159 // Even if those are already rendered, yield to the message loop before | 151 // Even if those are already rendered, yield to the message loop before |
| 160 // initiating searching. | 152 // initiating searching. |
| 161 this.showPages_ = {about: false, basic: true, advanced: true}; | 153 this.showPages_ = {about: false, basic: true, advanced: true}; |
| 162 setTimeout(function() { | 154 setTimeout(function() { |
| 163 settings.getSearchManager().search( | 155 settings.getSearchManager().search( |
| 164 query, assert(this.$$('settings-basic-page'))); | 156 query, assert(this.$$('settings-basic-page'))); |
| 165 }.bind(this), 0); | 157 }.bind(this), 0); |
| 166 setTimeout(function() { | 158 setTimeout(function() { |
| 167 settings.getSearchManager().search( | 159 settings.getSearchManager().search( |
| 168 query, assert(this.$$('settings-advanced-page'))); | 160 query, assert(this.$$('settings-advanced-page'))); |
| 169 }.bind(this), 0); | 161 }.bind(this), 0); |
| 170 }, | 162 }, |
| 171 }); | 163 }); |
| OLD | NEW |