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

Side by Side Diff: chrome/browser/resources/settings/checkbox/checkbox.js

Issue 1379483003: Rename cr-settings-elements (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 2 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 2015 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 * @fileoverview
7 * `cr-settings-checkbox` is a checkbox that controls a supplied preference.
8 *
9 * Example:
10 * <cr-settings-checkbox pref="{{prefs.settings.enableFoo}}"
11 * label="Enable foo setting." subLabel="(bar also)">
12 * </cr-settings-checkbox>
13 *
14 * @element cr-settings-checkbox
15 */
16 Polymer({
17 is: 'cr-settings-checkbox',
18
19 behaviors: [PolicyControllable],
20
21 properties: {
22 /**
23 * The boolean preference object to control.
24 * @type {?chrome.settingsPrivate.PrefObject}
25 */
26 pref: {
27 type: Object,
28 notify: true,
29 },
30
31 /** Whether the checkbox should represent the inverted value. */
32 inverted: {
33 type: Boolean,
34 value: false,
35 },
36
37 /** Whether the checkbox is checked. */
38 checked: {
39 type: Boolean,
40 value: false,
41 notify: true,
42 observer: 'checkedChanged_',
43 reflectToAttribute: true
44 },
45
46 /** Disabled property for the element. */
47 disabled: {
48 type: Boolean,
49 value: false,
50 notify: true,
51 reflectToAttribute: true
52 },
53
54 /** Checkbox label. */
55 label: {
56 type: String,
57 value: '',
58 },
59
60 /** Additional sub-label for the checkbox. */
61 subLabel: {
62 type: String,
63 value: '',
64 },
65 },
66
67 observers: [
68 'prefValueChanged_(pref.value)'
69 ],
70
71 /** @override */
72 ready: function() {
73 this.$.events.forward(this.$.checkbox, ['change']);
74 },
75
76 /**
77 * Polymer observer for pref.value.
78 * @param {*} prefValue
79 * @private
80 */
81 prefValueChanged_: function(prefValue) {
82 this.checked = this.getNewValue_(prefValue);
83 },
84
85 /**
86 * Polymer observer for checked.
87 * @private
88 */
89 checkedChanged_: function() {
90 this.set('pref.value', this.getNewValue_(this.checked));
91 },
92
93 /**
94 * @param {*} value
95 * @return {boolean} The value as a boolean, inverted if |inverted| is true.
96 * @private
97 */
98 getNewValue_: function(value) {
99 return this.inverted ? !value : !!value;
100 },
101
102 /**
103 * @param {boolean} disabled
104 * @param {?chrome.settingsPrivate.PrefObject} pref
105 * @return {boolean} Whether the checkbox should be disabled.
106 * @private
107 */
108 checkboxDisabled_: function(disabled, pref) {
109 return disabled || this.isPolicyControlled(pref);
110 },
111 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698