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

Unified 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, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/options/options_page.js
===================================================================
--- chrome/browser/resources/options/options_page.js (revision 0)
+++ chrome/browser/resources/options/options_page.js (revision 0)
@@ -0,0 +1,99 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+///////////////////////////////////////////////////////////////////////////////
+// OptionsPage class:
+
+/**
+ * Base class for options page.
+ * @constructor
+ * @param {string} name Options page name, also defines id of the div element
+ * containing the options view and the name of options page navigation bar
+ * item as name+'PageNav'.
+ * @param {string} title Options page title, used for navigation bar
+ */
+function OptionsPage(name, title, pageDivName) {
+ this.name = name;
+ this.title = title;
+ this.pageDivName = pageDivName;
+ this.pageDiv = $(this.pageDivName);
+ this.tab = null;
+}
+
+OptionsPage.registeredPages_ = {};
+
+/**
+ * Shows a registered page.
+ * @param {string} pageName Page name.
+ */
+OptionsPage.showPageByName = function(pageName) {
+ for (var name in OptionsPage.registeredPages_) {
+ var page = OptionsPage.registeredPages_[name];
+ page.visible = name == pageName;
+ }
+};
+
+OptionsPage.setState = function(state) {
+ if (state.pageName)
+ OptionsPage.showPageByName(state.pageName);
+};
+
+/**
+ * Registers new options page.
+ * @param {OptionsPage} page Page to register, must be of a class derived from
+ * OptionsPage.
+ */
+OptionsPage.register = function(page) {
+ OptionsPage.registeredPages_[page.name] = page;
+ // Create and add new page <li> element to navbar.
+ var pageNav = document.createElement('li');
+ pageNav.id = page.name + 'PageNav';
+ pageNav.className = 'navbar-item';
+ pageNav.setAttribute('pageName', page.name);
+ pageNav.textContent = page.title;
+ pageNav.onclick = function(event) {
+ OptionsPage.showPageByName(this.getAttribute('pageName'));
+ };
+ var navbar = $('navbar');
+ navbar.appendChild(pageNav);
+ page.tab = pageNav;
+ page.initializePage();
+};
+
+OptionsPage.prototype = {
+ /**
+ * Initializes page content.
+ */
+ initializePage: function() {},
+
+ /**
+ * Gets page visibility state.
+ */
+ get visible() {
+ var page = $(this.pageDivName);
+ return page.ownerDocument.defaultView.getComputedStyle(
+ page).visibility == 'visible';
+ },
+
+ /**
+ * Sets page visibility.
+ */
+ set visible(visible) {
+ if ((this.visible && visible) || (!this.visible && !visible))
+ return;
+
+ if (visible) {
+ window.history.pushState({pageName: this.name},
+ this.title,
+ '/' + this.name);
+ this.pageDiv.style.visibility = 'visible';
+ this.tab.classList.add('navbar-item-selected');
+ } else {
+ this.pageDiv.style.visibility = 'hidden';
+ this.tab.classList.remove('navbar-item-selected');
+ }
+ }
+};
+
+
Property changes on: chrome/browser/resources/options/options_page.js
___________________________________________________________________
Added: svn:eol-style
+ LF
« 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