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

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

Issue 1346833003: Lazy init prefs in MD Settings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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
« no previous file with comments | « no previous file | chrome/browser/resources/settings/prefs/prefs.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 * `cr-settings-checkbox` is a checkbox that controls a supplied preference. 7 * `cr-settings-checkbox` is a checkbox that controls a supplied preference.
8 * 8 *
9 * Example: 9 * Example:
10 * <cr-settings-checkbox pref="{{prefs.settings.enableFoo}}" 10 * <cr-settings-checkbox pref="{{prefs.settings.enableFoo}}"
11 * label="Enable foo setting." subLabel="(bar also)"> 11 * label="Enable foo setting." subLabel="(bar also)">
12 * </cr-settings-checkbox> 12 * </cr-settings-checkbox>
13 * 13 *
14 * @element cr-settings-checkbox 14 * @element cr-settings-checkbox
15 */ 15 */
16 Polymer({ 16 Polymer({
17 is: 'cr-settings-checkbox', 17 is: 'cr-settings-checkbox',
18 18
19 properties: { 19 properties: {
20 /** 20 /**
21 * The boolean preference object to control. 21 * The boolean preference object to control.
22 * @type {?chrome.settingsPrivate.PrefObject} 22 * @type {?chrome.settingsPrivate.PrefObject}
23 */ 23 */
24 pref: { 24 pref: {
25 type: Object, 25 type: Object,
26 notify: true, 26 notify: true,
27 value: null
28 }, 27 },
29 28
30 inverted: { 29 inverted: {
31 type: Boolean, 30 type: Boolean,
32 value: false 31 value: false
33 }, 32 },
34 33
35 checked: { 34 checked: {
36 type: Boolean, 35 type: Boolean,
37 value: false, 36 value: false,
(...skipping 15 matching lines...) Expand all
53 'prefValueChanged_(pref.value)' 52 'prefValueChanged_(pref.value)'
54 ], 53 ],
55 54
56 /** @override */ 55 /** @override */
57 ready: function() { 56 ready: function() {
58 this.$.events.forward(this.$.checkbox, ['change']); 57 this.$.events.forward(this.$.checkbox, ['change']);
59 }, 58 },
60 59
61 /** @private */ 60 /** @private */
62 prefValueChanged_: function(prefValue) { 61 prefValueChanged_: function(prefValue) {
63 // prefValue is initially undefined when Polymer initializes pref. 62 this.checked = this.getNewValue_(prefValue);
64 if (prefValue !== undefined) {
65 this.checked = this.getNewValue_(prefValue);
66 }
67 }, 63 },
68 64
69 /** @private */ 65 /** @private */
70 checkedChanged_: function() { 66 checkedChanged_: function() {
71 if (this.pref) { 67 if (this.pref) {
72 this.set('pref.value', this.getNewValue_(this.checked)); 68 this.set('pref.value', this.getNewValue_(this.checked));
73 } 69 }
74 }, 70 },
75 71
76 /** @private */ 72 /** @private */
77 getNewValue_: function(val) { 73 getNewValue_: function(val) {
78 return this.inverted ? !val : val; 74 return this.inverted ? !val : val;
79 } 75 }
80 }); 76 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/settings/prefs/prefs.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698