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

Unified 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, 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
index 9d59dd6e1b611e29d27957bbfe9a19d3589334f1..a0fc85fe597b8c59cfacab703d1706f37dabbf10 100644
--- a/chrome/browser/resources/chromeos/switch_access/options.js
+++ b/chrome/browser/resources/chromeos/switch_access/options.js
@@ -41,9 +41,9 @@ SwitchAccessOptions.prototype = {
* @private
*/
init_: function() {
- let prefs = this.switchAccessPrefs_.getPrefs();
- $('enableAutoScan').checked = prefs['enableAutoScan'];
- $('autoScanTime').value = prefs['autoScanTime'];
+ $('enableAutoScan').checked =
+ this.switchAccessPrefs_.getPref('enableAutoScan');
+ $('autoScanTime').value = this.switchAccessPrefs_.getPref('autoScanTime');
},
/**
@@ -53,17 +53,40 @@ SwitchAccessOptions.prototype = {
* @private
*/
handleInputChange_: function(event) {
- switch (event.target.id) {
+ let input = event.target;
+ switch (input.id) {
case 'enableAutoScan':
- this.switchAccessPrefs_.setPref(event.target.id, event.target.checked);
+ this.switchAccessPrefs_.setPref(input.id, input.checked);
break;
case 'autoScanTime':
- this.switchAccessPrefs_.setPref(event.target.id, event.target.value);
+ let oldVal =
+ /** @type {number} */ (this.switchAccessPrefs_.getPref(input.id));
+ let val = Number(input.value);
+ let min = Number(input.min);
+ if (this.isValidInput_(val, oldVal, min)) {
+ input.value = val;
+ this.switchAccessPrefs_.setPref(input.id, val);
+ } else {
+ input.value = oldVal;
+ }
break;
}
},
/**
+ * Return true if the input is a valid autoScanTime input. Otherwise, return
+ * false.
+ *
+ * @param {number} value
+ * @param {number} oldValue
+ * @param {number} min
+ * @return {boolean}
+ */
+ isValidInput_: function(value, oldValue, min) {
+ return (value !== oldValue) && (value >= min);
+ },
+
+ /**
* Handle a change in user preferences.
*
* @param {!Event} event

Powered by Google App Engine
This is Rietveld 408576698