Chromium Code Reviews| OLD | NEW |
|---|---|
| 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}}" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 | 50 |
| 51 observers: [ | 51 observers: [ |
| 52 'prefValueChanged_(pref.value)' | 52 'prefValueChanged_(pref.value)' |
| 53 ], | 53 ], |
| 54 | 54 |
| 55 /** @override */ | 55 /** @override */ |
| 56 ready: function() { | 56 ready: function() { |
| 57 this.$.events.forward(this.$.checkbox, ['change']); | 57 this.$.events.forward(this.$.checkbox, ['change']); |
| 58 }, | 58 }, |
| 59 | 59 |
| 60 /** @override */ | |
| 61 attached: function() { | |
| 62 // HACK(dschuyler): paper-checkbox 1.0.6 will hide the label | |
| 63 // if the content is empty. | |
| 64 // TODO(dschuyler): rework settings checkbox to use content | |
| 65 // rather than spans. | |
| 66 this.$.checkbox.$.checkbox.$.checkboxLabel.hidden = false; | |
| 67 }, | |
|
stevenjb
2015/08/13 21:44:38
Is there any reason why this was done here instead
| |
| 68 | |
| 60 /** @private */ | 69 /** @private */ |
| 61 prefValueChanged_: function(prefValue) { | 70 prefValueChanged_: function(prefValue) { |
| 62 // prefValue is initially undefined when Polymer initializes pref. | 71 // prefValue is initially undefined when Polymer initializes pref. |
| 63 if (prefValue !== undefined) { | 72 if (prefValue !== undefined) { |
| 64 this.checked = this.getNewValue_(prefValue); | 73 this.checked = this.getNewValue_(prefValue); |
| 65 } | 74 } |
| 66 }, | 75 }, |
| 67 | 76 |
| 68 /** @private */ | 77 /** @private */ |
| 69 checkedChanged_: function() { | 78 checkedChanged_: function() { |
| 70 if (this.pref) { | 79 if (this.pref) { |
| 71 this.pref.value = this.getNewValue_(this.checked); | 80 this.pref.value = this.getNewValue_(this.checked); |
| 72 } | 81 } |
| 73 }, | 82 }, |
| 74 | 83 |
| 75 /** @private */ | 84 /** @private */ |
| 76 getNewValue_: function(val) { | 85 getNewValue_: function(val) { |
| 77 return this.inverted ? !val : val; | 86 return this.inverted ? !val : val; |
| 78 } | 87 } |
| 79 }); | 88 }); |
| OLD | NEW |