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

Side by Side Diff: chrome/browser/resources/chromeos/switch_access/options.js

Issue 2760453002: Creating options page and storing preferences. (Closed)
Patch Set: Fixing change made to compiled_resources2.gyp 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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 * Alias for document.getElementById.
7 *
8 * @param {string} id
9 * @return {Element}
10 */
11 let $ = function(id) {
12 let el = document.getElementById(id);
13 return el;
14 }
15
16 /**
17 * Class to manage the options page.
18 *
19 * @constructor
20 */
21 let SwitchAccessOptions = function() {
22 let background = chrome.extension.getBackgroundPage();
23
24 /**
25 * User preferences.
26 *
27 * @private
28 */
29 this.switchAccessPrefs_ = background.switchAccess.switchAccessPrefs;
30
31 document.addEventListener('DOMContentLoaded', this.init_.bind(this));
dmazzoni 2017/03/22 21:53:53 Does 'load' work? Another thing I usually do is j
elichtenberg 2017/03/22 23:02:29 'load' would work too, but 'DOMContentLoaded' is a
32 document.addEventListener('change', this.handleInputChange_.bind(this));
33 background.document.addEventListener('prefsUpdate', this.handlePrefsUpdate_);
34 };
35
36 SwitchAccessOptions.prototype = {
37 /**
38 * Initialize the options page by setting all elements representing a user
39 * preference to show the correct value.
40 *
41 * @private
42 */
43 init_: function() {
44 let prefs = this.switchAccessPrefs_.getPrefs();
45 $('enableAutoScan').checked = prefs['enableAutoScan'];
46 $('autoScanTime').value = prefs['autoScanTime'];
47 },
48
49 /**
50 * Handle a change by the user to an element representing a user preference.
51 *
52 * @param {!Event} event
53 * @private
54 */
55 handleInputChange_: function(event) {
56 switch (event.target.id) {
57 case 'enableAutoScan':
58 this.switchAccessPrefs_.setPref(event.target.id, event.target.checked);
59 break;
60 case 'autoScanTime':
61 this.switchAccessPrefs_.setPref(event.target.id, event.target.value);
62 break;
63 }
64 },
65
66 /**
67 * Handle a change in user preferences.
68 *
69 * @param {!Event} event
70 * @private
71 */
72 handlePrefsUpdate_: function(event) {
73 if (document.readyState === 'interactive' ||
dmazzoni 2017/03/22 21:53:54 rather than checking document.readyState, how abou
elichtenberg 2017/03/22 23:02:29 Done. I agree, that does look better.
74 document.readyState === 'complete') {
75 let updatedPrefs = event.detail;
76 for (let key of Object.keys(updatedPrefs)) {
77 switch (key) {
78 case 'enableAutoScan':
79 $(key).checked = updatedPrefs[key];
80 break;
81 case 'autoScanTime':
82 $(key).value = updatedPrefs[key];
83 break;
84 }
85 }
86 }
87 }
88 };
89
90 new SwitchAccessOptions();
OLDNEW
« 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