OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // PrefCheckbox class: | 6 // PrefCheckbox class: |
7 | 7 |
8 // Define a constructor that uses an input element as its underlying element. | 8 // Define a constructor that uses an input element as its underlying element. |
9 var PrefCheckbox = cr.ui.define('input'); | 9 var PrefCheckbox = cr.ui.define('input'); |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 } | 34 } |
35 }; | 35 }; |
36 | 36 |
37 /** | 37 /** |
38 * The preference name. | 38 * The preference name. |
39 * @type {string} | 39 * @type {string} |
40 */ | 40 */ |
41 cr.defineProperty(PrefCheckbox, 'pref', cr.PropertyKind.ATTR); | 41 cr.defineProperty(PrefCheckbox, 'pref', cr.PropertyKind.ATTR); |
42 | 42 |
43 /////////////////////////////////////////////////////////////////////////////// | 43 /////////////////////////////////////////////////////////////////////////////// |
44 // PrefRadio class: | |
45 | |
46 // Define a constructor that uses an input element as its underlying element. | |
47 var PrefRadio = cr.ui.define('input'); | |
48 | |
49 PrefRadio.prototype = { | |
50 // Set up the prototype chain | |
51 __proto__: HTMLInputElement.prototype, | |
52 | |
53 /** | |
54 * Initialization function for the cr.ui framework. | |
55 */ | |
56 decorate: function() { | |
57 this.type = 'radio'; | |
58 var self = this; | |
59 | |
60 // Listen to pref changes. | |
61 Preferences.getInstance().addEventListener(this.pref, | |
62 function(event) { | |
63 self.checked = String(event.value) == self.value; | |
64 }); | |
65 | |
66 // Listen to user events. | |
67 this.addEventListener('change', | |
68 function(e) { | |
69 if(self.value == 'true' || self.value == 'false') { | |
70 Preferences.setBooleanPref(self.pref, | |
71 self.value == 'true'); | |
72 }else { | |
73 Preferences.setIntegerPref(self.pref, | |
74 parseInt(self.value, 10)); | |
75 } | |
76 }); | |
77 }, | |
78 | |
79 /** | |
80 * Getter for preference name attribute. | |
81 */ | |
82 get pref() { | |
83 return this.getAttribute('pref'); | |
84 }, | |
85 | |
86 /** | |
87 * Setter for preference name attribute. | |
88 */ | |
89 set pref(name) { | |
90 this.setAttribute('pref', name); | |
91 } | |
92 }; | |
93 | |
94 | |
95 /////////////////////////////////////////////////////////////////////////////// | |
96 // PrefRange class: | 44 // PrefRange class: |
97 | 45 |
98 // Define a constructor that uses an input element as its underlying element. | 46 // Define a constructor that uses an input element as its underlying element. |
99 var PrefRange = cr.ui.define('input'); | 47 var PrefRange = cr.ui.define('input'); |
100 | 48 |
101 PrefRange.prototype = { | 49 PrefRange.prototype = { |
102 // Set up the prototype chain | 50 // Set up the prototype chain |
103 __proto__: HTMLInputElement.prototype, | 51 __proto__: HTMLInputElement.prototype, |
104 | 52 |
105 /** | 53 /** |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 this.appendChild(new Option(values[1], values[0])); | 125 this.appendChild(new Option(values[1], values[0])); |
178 }, this); | 126 }, this); |
179 } | 127 } |
180 }; | 128 }; |
181 | 129 |
182 /** | 130 /** |
183 * The preference name. | 131 * The preference name. |
184 * @type {string} | 132 * @type {string} |
185 */ | 133 */ |
186 cr.defineProperty(PrefSelect, 'pref', cr.PropertyKind.ATTR); | 134 cr.defineProperty(PrefSelect, 'pref', cr.PropertyKind.ATTR); |
OLD | NEW |