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

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

Issue 2777203006: Added auto-scan, made some small changes to how prefs are stored, refactored. (Closed)
Patch Set: Created 3 years, 8 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * Alias for document.getElementById. 6 * Alias for document.getElementById.
7 * 7 *
8 * @param {string} id 8 * @param {string} id
9 * @return {Element} 9 * @return {Element}
10 */ 10 */
(...skipping 23 matching lines...) Expand all
34 }; 34 };
35 35
36 SwitchAccessOptions.prototype = { 36 SwitchAccessOptions.prototype = {
37 /** 37 /**
38 * Initialize the options page by setting all elements representing a user 38 * Initialize the options page by setting all elements representing a user
39 * preference to show the correct value. 39 * preference to show the correct value.
40 * 40 *
41 * @private 41 * @private
42 */ 42 */
43 init_: function() { 43 init_: function() {
44 let prefs = this.switchAccessPrefs_.getPrefs(); 44 $('enableAutoScan').checked =
45 $('enableAutoScan').checked = prefs['enableAutoScan']; 45 this.switchAccessPrefs_.getPref('enableAutoScan');
46 $('autoScanTime').value = prefs['autoScanTime']; 46 $('autoScanTime').value = this.switchAccessPrefs_.getPref('autoScanTime');
47 }, 47 },
48 48
49 /** 49 /**
50 * Handle a change by the user to an element representing a user preference. 50 * Handle a change by the user to an element representing a user preference.
51 * 51 *
52 * @param {!Event} event 52 * @param {!Event} event
53 * @private 53 * @private
54 */ 54 */
55 handleInputChange_: function(event) { 55 handleInputChange_: function(event) {
56 switch (event.target.id) { 56 let input = event.target;
57 switch (input.id) {
57 case 'enableAutoScan': 58 case 'enableAutoScan':
58 this.switchAccessPrefs_.setPref(event.target.id, event.target.checked); 59 this.switchAccessPrefs_.setPref(input.id, input.checked);
59 break; 60 break;
60 case 'autoScanTime': 61 case 'autoScanTime':
61 this.switchAccessPrefs_.setPref(event.target.id, event.target.value); 62 let oldVal =
63 /** @type {number} */ (this.switchAccessPrefs_.getPref(input.id));
64 let val = Number(input.value);
65 let min = Number(input.min);
66 if (this.isValidInput_(val, oldVal, min)) {
67 input.value = val;
68 this.switchAccessPrefs_.setPref(input.id, val);
69 } else {
70 input.value = oldVal;
71 }
62 break; 72 break;
63 } 73 }
64 }, 74 },
65 75
66 /** 76 /**
77 * Return true if the input is a valid autoScanTime input. Otherwise, return
78 * false.
79 *
80 * @param {number} value
81 * @param {number} oldValue
82 * @param {number} min
83 * @return {boolean}
84 */
85 isValidInput_: function(value, oldValue, min) {
86 return (value !== oldValue) && (value >= min);
87 },
88
89 /**
67 * Handle a change in user preferences. 90 * Handle a change in user preferences.
68 * 91 *
69 * @param {!Event} event 92 * @param {!Event} event
70 * @private 93 * @private
71 */ 94 */
72 handlePrefsUpdate_: function(event) { 95 handlePrefsUpdate_: function(event) {
73 let updatedPrefs = event.detail; 96 let updatedPrefs = event.detail;
74 for (let key of Object.keys(updatedPrefs)) { 97 for (let key of Object.keys(updatedPrefs)) {
75 switch (key) { 98 switch (key) {
76 case 'enableAutoScan': 99 case 'enableAutoScan':
77 $(key).checked = updatedPrefs[key]; 100 $(key).checked = updatedPrefs[key];
78 break; 101 break;
79 case 'autoScanTime': 102 case 'autoScanTime':
80 $(key).value = updatedPrefs[key]; 103 $(key).value = updatedPrefs[key];
81 break; 104 break;
82 } 105 }
83 } 106 }
84 } 107 }
85 }; 108 };
86 109
87 document.addEventListener('DOMContentLoaded', function() { 110 document.addEventListener('DOMContentLoaded', function() {
88 new SwitchAccessOptions(); 111 new SwitchAccessOptions();
89 }); 112 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698