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

Unified Diff: chrome/browser/resources/chromeos/switch_access/options.js

Issue 2760453002: Creating options page and storing preferences. (Closed)
Patch Set: Responded to comments Created 3 years, 9 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/chromeos/switch_access/options.js
diff --git a/chrome/browser/resources/chromeos/switch_access/options.js b/chrome/browser/resources/chromeos/switch_access/options.js
new file mode 100644
index 0000000000000000000000000000000000000000..9d59dd6e1b611e29d27957bbfe9a19d3589334f1
--- /dev/null
+++ b/chrome/browser/resources/chromeos/switch_access/options.js
@@ -0,0 +1,89 @@
+// Copyright 2017 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.
+
+/**
+ * Alias for document.getElementById.
+ *
+ * @param {string} id
+ * @return {Element}
+ */
+let $ = function(id) {
+ return document.getElementById(id);
+};
+
+/**
+ * Class to manage the options page.
+ *
+ * @constructor
+ */
+let SwitchAccessOptions = function() {
+ let background = chrome.extension.getBackgroundPage();
+
+ /**
+ * User preferences.
+ *
+ * @type {SwitchAccessPrefs}
+ */
+ this.switchAccessPrefs_ = background.switchAccess.switchAccessPrefs;
+
+ this.init_();
+ document.addEventListener('change', this.handleInputChange_.bind(this));
+ background.document.addEventListener(
+ 'prefsUpdate', this.handlePrefsUpdate_.bind(this));
+};
+
+SwitchAccessOptions.prototype = {
+ /**
+ * Initialize the options page by setting all elements representing a user
+ * preference to show the correct value.
+ *
+ * @private
+ */
+ init_: function() {
+ let prefs = this.switchAccessPrefs_.getPrefs();
+ $('enableAutoScan').checked = prefs['enableAutoScan'];
+ $('autoScanTime').value = prefs['autoScanTime'];
+ },
+
+ /**
+ * Handle a change by the user to an element representing a user preference.
+ *
+ * @param {!Event} event
+ * @private
+ */
+ handleInputChange_: function(event) {
+ switch (event.target.id) {
+ case 'enableAutoScan':
+ this.switchAccessPrefs_.setPref(event.target.id, event.target.checked);
+ break;
+ case 'autoScanTime':
+ this.switchAccessPrefs_.setPref(event.target.id, event.target.value);
+ break;
+ }
+ },
+
+ /**
+ * Handle a change in user preferences.
+ *
+ * @param {!Event} event
+ * @private
+ */
+ handlePrefsUpdate_: function(event) {
+ let updatedPrefs = event.detail;
+ for (let key of Object.keys(updatedPrefs)) {
+ switch (key) {
+ case 'enableAutoScan':
+ $(key).checked = updatedPrefs[key];
+ break;
+ case 'autoScanTime':
+ $(key).value = updatedPrefs[key];
+ break;
+ }
+ }
+ }
+};
+
+document.addEventListener('DOMContentLoaded', function() {
+ new SwitchAccessOptions();
+});
« no previous file with comments | « chrome/browser/resources/chromeos/switch_access/options.html ('k') | chrome/browser/resources/chromeos/switch_access/prefs.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698