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

Unified Diff: chrome/browser/resources/options/pref_ui.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
« no previous file with comments | « chrome/browser/resources/options/options_page.js ('k') | chrome/browser/resources/options/preferences.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/options/pref_ui.js
===================================================================
--- chrome/browser/resources/options/pref_ui.js (revision 0)
+++ chrome/browser/resources/options/pref_ui.js (revision 0)
@@ -0,0 +1,160 @@
+// 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.
+
+///////////////////////////////////////////////////////////////////////////////
+// PrefCheckbox class:
+
+// Define a constructor that uses an input element as its underlying element.
+var PrefCheckbox = cr.ui.define('input');
+
+PrefCheckbox.prototype = {
+ // Set up the prototype chain
+ __proto__: HTMLInputElement.prototype,
+
+ /**
+ * Initialization function for the cr.ui framework.
+ */
+ decorate: function() {
+ this.type = 'checkbox';
+ var self = this;
+
+ // Listen to pref changes.
+ Preferences.getInstance().addEventListener(this.pref,
+ function(event) {
+ self.checked = event.value;
+ });
+
+ // Listen to user events.
+ this.addEventListener('click',
+ function(e) {
+ Preferences.setBooleanPref(self.pref,
+ self.checked);
+ });
+ },
+
+ /**
+ * Getter for preference name attribute.
+ */
+ get pref() {
+ return this.getAttribute('pref');
+ },
+
+ /**
+ * Setter for preference name attribute.
+ */
+ set pref(name) {
+ this.setAttribute('pref', name);
+ }
+};
+
+///////////////////////////////////////////////////////////////////////////////
+// PrefRange class:
+
+// Define a constructor that uses an input element as its underlying element.
+var PrefRange = cr.ui.define('input');
+
+PrefRange.prototype = {
+ // Set up the prototype chain
+ __proto__: HTMLInputElement.prototype,
+
+ /**
+ * Initialization function for the cr.ui framework.
+ */
+ decorate: function() {
+ this.type = 'range';
+ var self = this;
+
+ // Listen to pref changes.
+ Preferences.getInstance().addEventListener(this.pref,
+ function(event) {
+ self.value = event.value;
+ });
+
+ // Listen to user events.
+ this.addEventListener('change',
+ function(e) {
+ Preferences.setIntegerPref(self.pref, self.value);
+ });
+ },
+
+ /**
+ * Getter for preference name attribute.
+ */
+ get pref() {
+ return this.getAttribute('pref');
+ },
+
+ /**
+ * Setter for preference name attribute.
+ */
+ set pref(name) {
+ this.setAttribute('pref', name);
+ }
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// PrefSelect class:
+
+// Define a constructor that uses an select element as its underlying element.
+var PrefSelect = cr.ui.define('select');
+
+PrefSelect.prototype = {
+ // Set up the prototype chain
+ __proto__: HTMLSelectElement.prototype,
+
+ /**
+ * Initialization function for the cr.ui framework.
+ */
+ decorate: function() {
+ var self = this;
+ // Listen to pref changes.
+ Preferences.getInstance().addEventListener(this.pref,
+ function(event) {
+ for (var i = 0; i < self.options.length; i++) {
+ if (self.options[i].value == event.value) {
+ self.selectedIndex = i;
+ return;
+ }
+ }
+ self.selectedIndex = -1;
+ });
+
+ // Listen to user events.
+ this.addEventListener('change',
+ function(e) {
+ Preferences.setStringPref(self.pref,
+ self.options[self.selectedIndex].value);
+ });
+ },
+
+ /**
+ * Sets up options in select element.
+ * @param {Array} options List of option and their display text.
+ * Each string in the array contains options value and display text split
+ * with '|' character.
+ *
+ * TODO(zelidrag): move this to that i18n template classes.
+ */
+ initializeValues: function(options) {
+ var self = this;
+ options.forEach(function (option) {
+ var values = option.split('|');
+ self.appendChild(new Option(values[1], values[0], false, false));
+ });
+ },
+ /**
+ * Getter for preference name attribute.
+ */
+ get pref() {
+ return this.getAttribute('pref');
+ },
+
+ /**
+ * Setter for preference name attribute.
+ */
+ set pref(name) {
+ this.setAttribute('pref', name);
+ }
+};
Property changes on: chrome/browser/resources/options/pref_ui.js
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « chrome/browser/resources/options/options_page.js ('k') | chrome/browser/resources/options/preferences.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698