| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 cr.define('options', function() { | 5 cr.define('options', function() { |
| 6 ///////////////////////////////////////////////////////////////////////////// | 6 ///////////////////////////////////////////////////////////////////////////// |
| 7 // OptionsPage class: | 7 // OptionsPage class: |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Base class for options page. | 10 * Base class for options page. |
| 11 * @constructor | 11 * @constructor |
| 12 * @param {string} name Options page name, also defines id of the div element | 12 * @param {string} name Options page name, also defines id of the div element |
| 13 * containing the options view and the name of options page navigation bar | 13 * containing the options view and the name of options page navigation bar |
| 14 * item as name+'PageNav'. | 14 * item as name+'PageNav'. |
| 15 * @param {string} title Options page title, used for navigation bar | 15 * @param {string} title Options page title, used for navigation bar |
| 16 * @extends {EventTarget} | 16 * @extends {EventTarget} |
| 17 */ | 17 */ |
| 18 function OptionsPage(name, title, pageDivName) { | 18 function OptionsPage(name, title, pageDivName) { |
| 19 this.name = name; | 19 this.name = name; |
| 20 this.title = title; | 20 this.title = title; |
| 21 this.pageDivName = pageDivName; | 21 this.pageDivName = pageDivName; |
| 22 this.pageDiv = $(this.pageDivName); | 22 this.pageDiv = $(this.pageDivName); |
| 23 this.tab = null; | 23 this.tab = null; |
| 24 this.managed = false; |
| 24 } | 25 } |
| 25 | 26 |
| 26 OptionsPage.registeredPages_ = {}; | 27 OptionsPage.registeredPages_ = {}; |
| 27 | 28 |
| 28 /** | 29 /** |
| 29 * Pages which are meant to have an entry in the nav, but | 30 * Pages which are meant to have an entry in the nav, but |
| 30 * not have a permanent entry. | 31 * not have a permanent entry. |
| 31 */ | 32 */ |
| 32 OptionsPage.registeredSubPages_ = {}; | 33 OptionsPage.registeredSubPages_ = {}; |
| 33 | 34 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 161 |
| 161 OptionsPage.prototype = { | 162 OptionsPage.prototype = { |
| 162 __proto__: cr.EventTarget.prototype, | 163 __proto__: cr.EventTarget.prototype, |
| 163 | 164 |
| 164 /** | 165 /** |
| 165 * Initializes page content. | 166 * Initializes page content. |
| 166 */ | 167 */ |
| 167 initializePage: function() {}, | 168 initializePage: function() {}, |
| 168 | 169 |
| 169 /** | 170 /** |
| 171 * Sets managed banner visibility state. |
| 172 */ |
| 173 setManagedBannerVisibility: function(visible) { |
| 174 this.managed = visible; |
| 175 if (this.visible) { |
| 176 $('managed-prefs-banner').style.display = visible ? 'block' : 'none'; |
| 177 } |
| 178 }, |
| 179 |
| 180 /** |
| 170 * Gets page visibility state. | 181 * Gets page visibility state. |
| 171 */ | 182 */ |
| 172 get visible() { | 183 get visible() { |
| 173 var page = $(this.pageDivName); | 184 var page = $(this.pageDivName); |
| 174 return page && page.ownerDocument.defaultView.getComputedStyle( | 185 return page && page.ownerDocument.defaultView.getComputedStyle( |
| 175 page).display == 'block'; | 186 page).display == 'block'; |
| 176 }, | 187 }, |
| 177 | 188 |
| 178 /** | 189 /** |
| 179 * Sets page visibility. | 190 * Sets page visibility. |
| 180 */ | 191 */ |
| 181 set visible(visible) { | 192 set visible(visible) { |
| 182 if ((this.visible && visible) || (!this.visible && !visible)) | 193 if ((this.visible && visible) || (!this.visible && !visible)) |
| 183 return; | 194 return; |
| 184 | 195 |
| 185 if (visible) { | 196 if (visible) { |
| 186 this.pageDiv.style.display = 'block'; | 197 this.pageDiv.style.display = 'block'; |
| 187 if (this.isOverlay) { | 198 if (this.isOverlay) { |
| 188 var overlay = $('overlay'); | 199 var overlay = $('overlay'); |
| 189 overlay.classList.remove('hidden'); | 200 overlay.classList.remove('hidden'); |
| 190 } else { | 201 } else { |
| 202 var banner = $('managed-prefs-banner'); |
| 203 banner.style.display = this.managed ? 'block' : 'none'; |
| 204 |
| 191 // Recent webkit change no longer allows url change from "chrome://". | 205 // Recent webkit change no longer allows url change from "chrome://". |
| 192 window.history.pushState({pageName: this.name}, | 206 window.history.pushState({pageName: this.name}, |
| 193 this.title); | 207 this.title); |
| 194 } | 208 } |
| 195 if (this.tab) { | 209 if (this.tab) { |
| 196 this.tab.classList.add('navbar-item-selected'); | 210 this.tab.classList.add('navbar-item-selected'); |
| 197 if (this.tab.parentNode && this.tab.parentNode.id == 'subpagesnav') | 211 if (this.tab.parentNode && this.tab.parentNode.id == 'subpagesnav') |
| 198 this.tab.classList.remove('hidden'); | 212 this.tab.classList.remove('hidden'); |
| 199 } | 213 } |
| 200 } else { | 214 } else { |
| 201 if (this.isOverlay) { | 215 if (this.isOverlay) { |
| 202 var overlay = $('overlay'); | 216 var overlay = $('overlay'); |
| 203 overlay.classList.add('hidden'); | 217 overlay.classList.add('hidden'); |
| 204 } | 218 } |
| 205 this.pageDiv.style.display = 'none'; | 219 this.pageDiv.style.display = 'none'; |
| 206 if (this.tab) { | 220 if (this.tab) { |
| 207 this.tab.classList.remove('navbar-item-selected'); | 221 this.tab.classList.remove('navbar-item-selected'); |
| 208 if (this.tab.parentNode && this.tab.parentNode.id == 'subpagesnav') | 222 if (this.tab.parentNode && this.tab.parentNode.id == 'subpagesnav') |
| 209 this.tab.classList.add('hidden'); | 223 this.tab.classList.add('hidden'); |
| 210 } | 224 } |
| 211 } | 225 } |
| 212 | 226 |
| 213 cr.dispatchPropertyChange(this, 'visible', visible, !visible); | 227 cr.dispatchPropertyChange(this, 'visible', visible, !visible); |
| 214 } | 228 } |
| 215 }; | 229 }; |
| 216 | 230 |
| 217 // Export | 231 // Export |
| 218 return { | 232 return { |
| 219 OptionsPage: OptionsPage | 233 OptionsPage: OptionsPage |
| 220 }; | 234 }; |
| 221 | 235 |
| 222 }); | 236 }); |
| 223 | |
| OLD | NEW |