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. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 /** | 102 /** |
103 * Closes any currently-open subpage. | 103 * Closes any currently-open subpage. |
104 */ | 104 */ |
105 OptionsPage.closeSubPage = function() { | 105 OptionsPage.closeSubPage = function() { |
106 for (var name in OptionsPage.registeredSubPages_) { | 106 for (var name in OptionsPage.registeredSubPages_) { |
107 var pageInfo = OptionsPage.registeredSubPages_[name]; | 107 var pageInfo = OptionsPage.registeredSubPages_[name]; |
108 if (pageInfo.page.visible) { | 108 if (pageInfo.page.visible) { |
109 pageInfo.page.visible = false; | 109 pageInfo.page.visible = false; |
110 // Since the managed pref banner lives outside the overlay, and the | 110 // Since the managed pref banner lives outside the overlay, and the |
111 // parent is not changing visibility, update the banner explicitly. | 111 // parent is not changing visibility, update the banner explicitly. |
112 var banner = $('managed-prefs-banner'); | 112 pageInfo.parentPage.updateManagedBannerVisibility(); |
113 banner.style.display = pageInfo.parentPage.managed ? 'block' : 'none'; | |
114 } | 113 } |
115 } | 114 } |
116 }; | 115 }; |
117 | 116 |
118 /** | 117 /** |
119 * Shows the tab contents for the given navigation tab. | 118 * Shows the tab contents for the given navigation tab. |
120 * @param {!Element} tab The tab that the user clicked. | 119 * @param {!Element} tab The tab that the user clicked. |
121 */ | 120 */ |
122 OptionsPage.showTab = function(tab) { | 121 OptionsPage.showTab = function(tab) { |
123 // Search parents until we find a tab, or the nav bar itself. This allows | 122 // Search parents until we find a tab, or the nav bar itself. This allows |
124 // tabs to have child nodes, e.g. labels in separately-styled spans. | 123 // tabs to have child nodes, e.g. labels in separately-styled spans. |
125 while (tab && !tab.classList.contains('subpages-nav-tabs') && | 124 while (tab && !tab.classList.contains('subpages-nav-tabs') && |
126 !tab.classList.contains('inactive-tab')) { | 125 !tab.classList.contains('inactive-tab')) { |
127 tab = tab.parentNode; | 126 tab = tab.parentNode; |
128 } | 127 } |
129 if (!tab || !tab.classList.contains('inactive-tab')) | 128 if (!tab || !tab.classList.contains('inactive-tab')) |
130 return; | 129 return; |
131 | 130 |
132 if (this.activeNavTab != null) { | 131 if (this.activeNavTab != null) { |
133 this.activeNavTab.classList.remove('active-tab'); | 132 this.activeNavTab.classList.remove('active-tab'); |
134 $(this.activeNavTab.getAttribute('tab-contents')).classList. | 133 $(this.activeNavTab.getAttribute('tab-contents')).classList. |
135 remove('active-tab-contents'); | 134 remove('active-tab-contents'); |
136 } | 135 } |
137 | 136 |
138 tab.classList.add('active-tab'); | 137 tab.classList.add('active-tab'); |
139 $(tab.getAttribute('tab-contents')).classList.add('active-tab-contents'); | 138 $(tab.getAttribute('tab-contents')).classList.add('active-tab-contents'); |
140 this.activeNavTab = tab; | 139 this.activeNavTab = tab; |
141 } | 140 }; |
142 | 141 |
143 /** | 142 /** |
144 * Registers new options page. | 143 * Registers new options page. |
145 * @param {OptionsPage} page Page to register. | 144 * @param {OptionsPage} page Page to register. |
146 */ | 145 */ |
147 OptionsPage.register = function(page) { | 146 OptionsPage.register = function(page) { |
148 OptionsPage.registeredPages_[page.name] = page; | 147 OptionsPage.registeredPages_[page.name] = page; |
149 // Create and add new page <li> element to navbar. | 148 // Create and add new page <li> element to navbar. |
150 var pageNav = document.createElement('li'); | 149 var pageNav = document.createElement('li'); |
151 pageNav.id = page.name + 'PageNav'; | 150 pageNav.id = page.name + 'PageNav'; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 * Initializes page content. | 224 * Initializes page content. |
226 */ | 225 */ |
227 initializePage: function() {}, | 226 initializePage: function() {}, |
228 | 227 |
229 /** | 228 /** |
230 * Sets managed banner visibility state. | 229 * Sets managed banner visibility state. |
231 */ | 230 */ |
232 setManagedBannerVisibility: function(visible) { | 231 setManagedBannerVisibility: function(visible) { |
233 this.managed = visible; | 232 this.managed = visible; |
234 if (this.visible) { | 233 if (this.visible) { |
235 $('managed-prefs-banner').style.display = visible ? 'block' : 'none'; | 234 this.updateManagedBannerVisibility(); |
| 235 } |
| 236 }, |
| 237 |
| 238 /** |
| 239 * Updates managed banner visibility state. |
| 240 */ |
| 241 updateManagedBannerVisibility: function() { |
| 242 if (this.managed) { |
| 243 $('managed-prefs-banner').classList.remove('hidden'); |
| 244 } else { |
| 245 $('managed-prefs-banner').classList.add('hidden'); |
236 } | 246 } |
237 }, | 247 }, |
238 | 248 |
239 /** | 249 /** |
240 * Gets page visibility state. | 250 * Gets page visibility state. |
241 */ | 251 */ |
242 get visible() { | 252 get visible() { |
243 var page = $(this.pageDivName); | 253 var page = $(this.pageDivName); |
244 return page && page.ownerDocument.defaultView.getComputedStyle( | 254 return page && page.ownerDocument.defaultView.getComputedStyle( |
245 page).display == 'block'; | 255 page).display == 'block'; |
246 }, | 256 }, |
247 | 257 |
248 /** | 258 /** |
249 * Sets page visibility. | 259 * Sets page visibility. |
250 */ | 260 */ |
251 set visible(visible) { | 261 set visible(visible) { |
252 if ((this.visible && visible) || (!this.visible && !visible)) | 262 if ((this.visible && visible) || (!this.visible && !visible)) |
253 return; | 263 return; |
254 | 264 |
255 if (visible) { | 265 if (visible) { |
256 this.pageDiv.style.display = 'block'; | 266 this.pageDiv.classList.remove('hidden'); |
257 if (this.isOverlay) { | 267 if (this.isOverlay) { |
258 var overlay = $('overlay'); | 268 $('overlay').classList.remove('hidden'); |
259 overlay.classList.remove('hidden'); | |
260 document.addEventListener('keydown', | 269 document.addEventListener('keydown', |
261 OptionsPage.clearOverlaysOnEsc_); | 270 OptionsPage.clearOverlaysOnEsc_); |
262 } else { | 271 } else { |
263 if (this.isSubPageSheet) | 272 if (this.isSubPageSheet) |
264 $('subpage-sheet-container').classList.remove('hidden'); | 273 $('subpage-sheet-container').classList.remove('hidden'); |
265 | 274 |
266 var banner = $('managed-prefs-banner'); | 275 this.updateManagedBannerVisibility(); |
267 banner.style.display = this.managed ? 'block' : 'none'; | |
268 | 276 |
269 // Recent webkit change no longer allows url change from "chrome://". | 277 // Recent webkit change no longer allows url change from "chrome://". |
270 window.history.pushState({pageName: this.name}, | 278 window.history.pushState({pageName: this.name}, this.title); |
271 this.title); | |
272 } | 279 } |
273 if (this.tab) { | 280 if (this.tab) { |
274 this.tab.classList.add('navbar-item-selected'); | 281 this.tab.classList.add('navbar-item-selected'); |
275 } | 282 } |
276 } else { | 283 } else { |
| 284 this.pageDiv.classList.add('hidden'); |
277 if (this.isOverlay) { | 285 if (this.isOverlay) { |
278 var overlay = $('overlay'); | 286 $('overlay').classList.add('hidden'); |
279 overlay.classList.add('hidden'); | |
280 document.removeEventListener('keydown', | 287 document.removeEventListener('keydown', |
281 OptionsPage.clearOverlaysOnEsc_); | 288 OptionsPage.clearOverlaysOnEsc_); |
282 } else if (this.isSubPageSheet) { | 289 } else if (this.isSubPageSheet) { |
283 $('subpage-sheet-container').classList.add('hidden'); | 290 $('subpage-sheet-container').classList.add('hidden'); |
284 } | 291 } |
285 this.pageDiv.style.display = 'none'; | |
286 if (this.tab) { | 292 if (this.tab) { |
287 this.tab.classList.remove('navbar-item-selected'); | 293 this.tab.classList.remove('navbar-item-selected'); |
288 } | 294 } |
289 } | 295 } |
290 | 296 |
291 cr.dispatchPropertyChange(this, 'visible', visible, !visible); | 297 cr.dispatchPropertyChange(this, 'visible', visible, !visible); |
292 }, | 298 }, |
293 | 299 |
294 /** | 300 /** |
295 * Handles a hash value in the URL (such as bar in | 301 * Handles a hash value in the URL (such as bar in |
296 * chrome://options/foo#bar). Called on page load. By default, this shows | 302 * chrome://options/foo#bar). Called on page load. By default, this shows |
297 * an overlay that matches the hash name, but can be overriden by individual | 303 * an overlay that matches the hash name, but can be overriden by individual |
298 * OptionsPage subclasses to get other behavior. | 304 * OptionsPage subclasses to get other behavior. |
299 * @param {string} hash The hash value. | 305 * @param {string} hash The hash value. |
300 */ | 306 */ |
301 handleHash: function(hash) { | 307 handleHash: function(hash) { |
302 OptionsPage.showOverlay(hash); | 308 OptionsPage.showOverlay(hash); |
303 }, | 309 }, |
304 }; | 310 }; |
305 | 311 |
306 // Export | 312 // Export |
307 return { | 313 return { |
308 OptionsPage: OptionsPage | 314 OptionsPage: OptionsPage |
309 }; | 315 }; |
310 | 316 |
311 }); | 317 }); |
OLD | NEW |