Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(846)

Side by Side Diff: chrome/browser/resources/options/options_page.js

Issue 2835009: Split options page code/html into its own set of files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 ///////////////////////////////////////////////////////////////////////////////
6 // OptionsPage class:
7
8 /**
9 * Base class for options page.
10 * @constructor
11 * @param {string} name Options page name, also defines id of the div element
12 * containing the options view and the name of options page navigation bar
13 * item as name+'PageNav'.
14 * @param {string} title Options page title, used for navigation bar
15 */
16 function OptionsPage(name, title, pageDivName) {
17 this.name = name;
18 this.title = title;
19 this.pageDivName = pageDivName;
20 this.pageDiv = $(this.pageDivName);
21 this.tab = null;
22 }
23
24 OptionsPage.registeredPages_ = {};
25
26 /**
27 * Shows a registered page.
28 * @param {string} pageName Page name.
29 */
30 OptionsPage.showPageByName = function(pageName) {
31 for (var name in OptionsPage.registeredPages_) {
32 var page = OptionsPage.registeredPages_[name];
33 page.visible = name == pageName;
34 }
35 };
36
37 OptionsPage.setState = function(state) {
38 if (state.pageName)
39 OptionsPage.showPageByName(state.pageName);
40 };
41
42 /**
43 * Registers new options page.
44 * @param {OptionsPage} page Page to register, must be of a class derived from
45 * OptionsPage.
46 */
47 OptionsPage.register = function(page) {
48 OptionsPage.registeredPages_[page.name] = page;
49 // Create and add new page <li> element to navbar.
50 var pageNav = document.createElement('li');
51 pageNav.id = page.name + 'PageNav';
52 pageNav.className = 'navbar-item';
53 pageNav.setAttribute('pageName', page.name);
54 pageNav.textContent = page.title;
55 pageNav.onclick = function(event) {
56 OptionsPage.showPageByName(this.getAttribute('pageName'));
57 };
58 var navbar = $('navbar');
59 navbar.appendChild(pageNav);
60 page.tab = pageNav;
61 page.initializePage();
62 };
63
64 OptionsPage.prototype = {
65 /**
66 * Initializes page content.
67 */
68 initializePage: function() {},
69
70 /**
71 * Gets page visibility state.
72 */
73 get visible() {
74 var page = $(this.pageDivName);
75 return page.ownerDocument.defaultView.getComputedStyle(
76 page).visibility == 'visible';
77 },
78
79 /**
80 * Sets page visibility.
81 */
82 set visible(visible) {
83 if ((this.visible && visible) || (!this.visible && !visible))
84 return;
85
86 if (visible) {
87 window.history.pushState({pageName: this.name},
88 this.title,
89 '/' + this.name);
90 this.pageDiv.style.visibility = 'visible';
91 this.tab.classList.add('navbar-item-selected');
92 } else {
93 this.pageDiv.style.visibility = 'hidden';
94 this.tab.classList.remove('navbar-item-selected');
95 }
96 }
97 };
98
99
OLDNEW
« no previous file with comments | « chrome/browser/resources/options/chromeos_system_options.js ('k') | chrome/browser/resources/options/pref_ui.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698