Allow only one bookmark to be added for multiple fast starring
[chromium-blink-merge.git] / chrome / browser / resources / settings / checkbox / checkbox.js
blobd4bdeb4fc378da44e7864b61c7b6c070f9f80383
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.
5 /**
6 * @fileoverview
7 * `cr-settings-checkbox` is a checkbox that controls a supplied preference.
9 * Example:
10 * <cr-settings-checkbox pref="{{prefs.settings.enableFoo}}"
11 * label="Enable foo setting." subLabel="(bar also)">
12 * </cr-settings-checkbox>
14 * @element cr-settings-checkbox
16 Polymer({
17 is: 'cr-settings-checkbox',
19 properties: {
20 /**
21 * The boolean preference object to control.
22 * @type {?PrefObject}
24 pref: {
25 type: Object,
26 notify: true
29 inverted: {
30 type: Boolean,
31 value: false
34 checked: {
35 type: Boolean,
36 value: false,
37 observer: 'checkedChanged_'
40 label: {
41 type: String,
42 value: '',
45 subLabel: {
46 type: String,
47 value: '',
51 observers: [
52 'prefValueChanged_(pref.value)'
55 /** @override */
56 ready: function() {
57 this.$.events.forward(this.$.checkbox, ['change']);
60 /** @private */
61 prefValueChanged_: function(prefValue) {
62 // prefValue is initially undefined when Polymer initializes pref.
63 if (prefValue !== undefined) {
64 this.checked = this.getNewValue_(prefValue);
68 /** @private */
69 checkedChanged_: function() {
70 if (this.pref) {
71 this.pref.value = this.getNewValue_(this.checked);
75 /** @private */
76 getNewValue_: function(val) {
77 return this.inverted ? !val : val;
79 });