| 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 23 matching lines...) Expand all Loading... |
| 63 created: function() { | 63 created: function() { |
| 64 /** @private {!PromiseResolver} */ | 64 /** @private {!PromiseResolver} */ |
| 65 this.resolver_ = new PromiseResolver; | 65 this.resolver_ = new PromiseResolver; |
| 66 settings.main.rendered = this.resolver_.promise; | 66 settings.main.rendered = this.resolver_.promise; |
| 67 }, | 67 }, |
| 68 | 68 |
| 69 attached: function() { | 69 attached: function() { |
| 70 document.addEventListener('toggle-advanced-page', function(e) { | 70 document.addEventListener('toggle-advanced-page', function(e) { |
| 71 this.showAdvancedPage_ = e.detail; | 71 this.showAdvancedPage_ = e.detail; |
| 72 this.isAdvancedMenuOpen_ = e.detail; | 72 this.isAdvancedMenuOpen_ = e.detail; |
| 73 this.currentRoute = { | 73 settings.navigateTo(this.isAdvancedMenuOpen_ ? |
| 74 page: this.isAdvancedMenuOpen_ ? 'advanced' : 'basic', | 74 settings.Route.ADVANCED : settings.Route.BASIC); |
| 75 section: '', | |
| 76 subpage: [], | |
| 77 }; | |
| 78 if (this.showAdvancedPage_) { | 75 if (this.showAdvancedPage_) { |
| 79 doWhenReady( | 76 doWhenReady( |
| 80 function() { | 77 function() { |
| 81 var advancedPage = this.$$('settings-advanced-page'); | 78 var advancedPage = this.$$('settings-advanced-page'); |
| 82 return !!advancedPage && advancedPage.scrollHeight > 0; | 79 return !!advancedPage && advancedPage.scrollHeight > 0; |
| 83 }.bind(this), | 80 }.bind(this), |
| 84 function() { | 81 function() { |
| 85 this.$$('#toggleContainer').scrollIntoView(); | 82 this.$$('#toggleContainer').scrollIntoView(); |
| 86 }.bind(this)); | 83 }.bind(this)); |
| 87 } | 84 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 100 /** | 97 /** |
| 101 * @param {boolean} opened Whether the menu is expanded. | 98 * @param {boolean} opened Whether the menu is expanded. |
| 102 * @return {string} Which icon to use. | 99 * @return {string} Which icon to use. |
| 103 * @private | 100 * @private |
| 104 * */ | 101 * */ |
| 105 arrowState_: function(opened) { | 102 arrowState_: function(opened) { |
| 106 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; | 103 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; |
| 107 }, | 104 }, |
| 108 | 105 |
| 109 /** | 106 /** |
| 110 * @param {!SettingsRoute} newRoute | 107 * @param {!settings.Route} newRoute |
| 111 * @private | 108 * @private |
| 112 */ | 109 */ |
| 113 currentRouteChanged_: function(newRoute) { | 110 currentRouteChanged_: function(newRoute) { |
| 114 var isSubpage = !!newRoute.subpage.length; | 111 var isSubpage = !!newRoute.subpage.length; |
| 115 | 112 |
| 116 this.showAboutPage_ = newRoute.page == 'about'; | 113 this.showAboutPage_ = newRoute.page == 'about'; |
| 117 | 114 |
| 118 this.showAdvancedToggle_ = !this.showAboutPage_ && !isSubpage; | 115 this.showAdvancedToggle_ = !this.showAboutPage_ && !isSubpage; |
| 119 | 116 |
| 120 this.showBasicPage_ = this.showAdvancedToggle_ || newRoute.page == 'basic'; | 117 this.showBasicPage_ = this.showAdvancedToggle_ || newRoute.page == 'basic'; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 132 }, | 129 }, |
| 133 | 130 |
| 134 /** | 131 /** |
| 135 * Navigates to the default search page (if necessary). | 132 * Navigates to the default search page (if necessary). |
| 136 * @private | 133 * @private |
| 137 */ | 134 */ |
| 138 ensureInDefaultSearchPage_: function() { | 135 ensureInDefaultSearchPage_: function() { |
| 139 if (this.currentRoute.page != 'basic' || | 136 if (this.currentRoute.page != 'basic' || |
| 140 this.currentRoute.section != '' || | 137 this.currentRoute.section != '' || |
| 141 this.currentRoute.subpage.length != 0) { | 138 this.currentRoute.subpage.length != 0) { |
| 142 this.currentRoute = {page: 'basic', section: '', subpage: [], url: ''}; | 139 settings.navigateTo(settings.Route.BASIC); |
| 143 } | 140 } |
| 144 }, | 141 }, |
| 145 | 142 |
| 146 /** | 143 /** |
| 147 * @param {string} query | 144 * @param {string} query |
| 148 */ | 145 */ |
| 149 searchContents: function(query) { | 146 searchContents: function(query) { |
| 150 this.ensureInDefaultSearchPage_(); | 147 this.ensureInDefaultSearchPage_(); |
| 151 | 148 |
| 152 // Trigger rendering of the basic and advanced pages and search once ready. | 149 // Trigger rendering of the basic and advanced pages and search once ready. |
| 153 // Even if those are already rendered, yield to the message loop before | 150 // Even if those are already rendered, yield to the message loop before |
| 154 // initiating searching. | 151 // initiating searching. |
| 155 this.showBasicPage_ = true; | 152 this.showBasicPage_ = true; |
| 156 setTimeout(function() { | 153 setTimeout(function() { |
| 157 settings.search(query, assert(this.$$('settings-basic-page'))); | 154 settings.search(query, assert(this.$$('settings-basic-page'))); |
| 158 }.bind(this), 0); | 155 }.bind(this), 0); |
| 159 | 156 |
| 160 this.showAdvancedPage_ = true; | 157 this.showAdvancedPage_ = true; |
| 161 setTimeout(function() { | 158 setTimeout(function() { |
| 162 settings.search(query, assert(this.$$('settings-advanced-page'))); | 159 settings.search(query, assert(this.$$('settings-advanced-page'))); |
| 163 }.bind(this), 0); | 160 }.bind(this), 0); |
| 164 }, | 161 }, |
| 165 }); | 162 }); |
| OLD | NEW |