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

Side by Side Diff: chrome/browser/resources/settings/controls/settings_checkbox.js

Issue 1486953003: Support numbers in settings-checkbox (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase + Feedback Created 5 years 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
« no previous file with comments | « no previous file | chrome/test/data/webui/settings/checkbox_tests.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 * @fileoverview 6 * @fileoverview
7 * `settings-checkbox` is a checkbox that controls a supplied preference. 7 * `settings-checkbox` is a checkbox that controls a supplied preference.
8 * 8 *
9 * Example: 9 * Example:
10 * <settings-checkbox pref="{{prefs.settings.enableFoo}}" 10 * <settings-checkbox pref="{{prefs.settings.enableFoo}}"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 */ 80 */
81 prefValueChanged_: function(prefValue) { 81 prefValueChanged_: function(prefValue) {
82 this.checked = this.getNewValue_(prefValue); 82 this.checked = this.getNewValue_(prefValue);
83 }, 83 },
84 84
85 /** 85 /**
86 * Polymer observer for checked. 86 * Polymer observer for checked.
87 * @private 87 * @private
88 */ 88 */
89 checkedChanged_: function() { 89 checkedChanged_: function() {
90 this.set('pref.value', this.getNewValue_(this.checked)); 90 if (!this.pref)
91 return;
92 /** @type {boolean} */ var newValue = this.getNewValue_(this.checked);
93 // Ensure that newValue is the correct type for the pref type, either
94 // a boolean or a number.
95 if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) {
96 this.set('pref.value', newValue ? 1 : 0);
97 return;
98 }
99 this.set('pref.value', newValue);
91 }, 100 },
92 101
93 /** 102 /**
94 * @param {*} value 103 * @param {*} value
95 * @return {boolean} The value as a boolean, inverted if |inverted| is true. 104 * @return {boolean} The value as a boolean, inverted if |inverted| is true.
96 * @private 105 * @private
97 */ 106 */
98 getNewValue_: function(value) { 107 getNewValue_: function(value) {
99 return this.inverted ? !value : !!value; 108 return this.inverted ? !value : !!value;
100 }, 109 },
101 110
102 /** 111 /**
103 * @param {boolean} disabled 112 * @param {boolean} disabled
104 * @param {!chrome.settingsPrivate.PrefObject} pref 113 * @param {!chrome.settingsPrivate.PrefObject} pref
105 * @return {boolean} Whether the checkbox should be disabled. 114 * @return {boolean} Whether the checkbox should be disabled.
106 * @private 115 * @private
107 */ 116 */
108 checkboxDisabled_: function(disabled, pref) { 117 checkboxDisabled_: function(disabled, pref) {
109 return disabled || this.isPrefPolicyControlled(pref); 118 return disabled || this.isPrefPolicyControlled(pref);
110 }, 119 },
111 }); 120 });
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/webui/settings/checkbox_tests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698