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 cr.define('options', function() { | 5 cr.define('options', function() { |
6 | 6 |
7 var Preferences = options.Preferences; | 7 var Preferences = options.Preferences; |
8 ///////////////////////////////////////////////////////////////////////////// | 8 ///////////////////////////////////////////////////////////////////////////// |
9 // PrefCheckbox class: | 9 // PrefCheckbox class: |
10 | 10 |
11 // Define a constructor that uses an input element as its underlying element. | 11 // Define a constructor that uses an input element as its underlying element. |
12 var PrefCheckbox = cr.ui.define('input'); | 12 var PrefCheckbox = cr.ui.define('input'); |
13 | 13 |
14 PrefCheckbox.prototype = { | 14 PrefCheckbox.prototype = { |
15 // Set up the prototype chain | 15 // Set up the prototype chain |
16 __proto__: HTMLInputElement.prototype, | 16 __proto__: HTMLInputElement.prototype, |
17 | 17 |
18 /** | 18 /** |
19 * Initialization function for the cr.ui framework. | 19 * Initialization function for the cr.ui framework. |
20 */ | 20 */ |
21 decorate: function() { | 21 decorate: function() { |
22 this.type = 'checkbox'; | 22 this.type = 'checkbox'; |
23 var self = this; | 23 var self = this; |
24 | 24 |
25 // Listen to pref changes. | 25 // Listen to pref changes. |
26 Preferences.getInstance().addEventListener(this.pref, | 26 Preferences.getInstance().addEventListener(this.pref, |
27 function(event) { | 27 function(event) { |
28 var value = event.value && event.value['value'] != undefined ? | 28 var value = event.value && event.value['value'] != undefined ? |
29 event.value['value'] : event.value; | 29 event.value['value'] : event.value; |
30 self.checked = Boolean(value); | 30 // Invert pref value if inverted_pref == true. |
| 31 if (self.inverted_pref) |
| 32 self.checked = !Boolean(value); |
| 33 else |
| 34 self.checked = Boolean(value); |
31 self.managed = event.value && event.value['managed'] != undefined ? | 35 self.managed = event.value && event.value['managed'] != undefined ? |
32 event.value['managed'] : false; | 36 event.value['managed'] : false; |
33 self.disabled = self.managed; | 37 self.disabled = self.managed; |
34 // Honor manually_disabled property, so options pages can | 38 // Honor manually_disabled property, so options pages can |
35 // disable preferences manually when needed. | 39 // disable preferences manually when needed. |
36 if (self.manually_disabled) { | 40 if (self.manually_disabled) { |
37 self.disabled = true; | 41 self.disabled = true; |
38 } | 42 } |
39 }); | 43 }); |
40 | 44 |
41 // Listen to user events. | 45 // Listen to user events. |
42 this.addEventListener('click', | 46 this.addEventListener('click', |
43 function(e) { | 47 function(e) { |
| 48 var value = self.inverted_pref ? !self.checked : self.checked; |
44 switch(self.valueType) { | 49 switch(self.valueType) { |
45 case 'number': | 50 case 'number': |
46 Preferences.setIntegerPref(self.pref, | 51 Preferences.setIntegerPref(self.pref, |
47 Number(self.checked), self.metric); | 52 Number(value), self.metric); |
48 break; | 53 break; |
49 case 'boolean': | 54 case 'boolean': |
50 Preferences.setBooleanPref(self.pref, | 55 Preferences.setBooleanPref(self.pref, |
51 self.checked, self.metric); | 56 value, self.metric); |
52 break; | 57 break; |
53 } | 58 } |
54 }); | 59 }); |
55 | 60 |
56 // Initialize options. | 61 // Initialize options. |
57 this.ownerDocument.addEventListener('DOMContentLoaded', | 62 this.ownerDocument.addEventListener('DOMContentLoaded', |
58 function() { | 63 function() { |
59 self.initializeValueType(self.getAttribute('value-type')); | 64 self.initializeValueType(self.getAttribute('value-type')); |
60 }); | 65 }); |
61 }, | 66 }, |
(...skipping 12 matching lines...) Expand all Loading... |
74 * @type {string} | 79 * @type {string} |
75 */ | 80 */ |
76 cr.defineProperty(PrefCheckbox, 'pref', cr.PropertyKind.ATTR); | 81 cr.defineProperty(PrefCheckbox, 'pref', cr.PropertyKind.ATTR); |
77 | 82 |
78 /** | 83 /** |
79 * The user metric string. | 84 * The user metric string. |
80 * @type {string} | 85 * @type {string} |
81 */ | 86 */ |
82 cr.defineProperty(PrefCheckbox, 'metric', cr.PropertyKind.ATTR); | 87 cr.defineProperty(PrefCheckbox, 'metric', cr.PropertyKind.ATTR); |
83 | 88 |
| 89 /** |
| 90 * Whether to use inverted pref value. |
| 91 * @type {boolean} |
| 92 */ |
| 93 cr.defineProperty(PrefCheckbox, 'inverted_pref', cr.PropertyKind.BOOL_ATTR); |
| 94 |
84 ///////////////////////////////////////////////////////////////////////////// | 95 ///////////////////////////////////////////////////////////////////////////// |
85 // PrefRadio class: | 96 // PrefRadio class: |
86 | 97 |
87 //Define a constructor that uses an input element as its underlying element. | 98 //Define a constructor that uses an input element as its underlying element. |
88 var PrefRadio = cr.ui.define('input'); | 99 var PrefRadio = cr.ui.define('input'); |
89 | 100 |
90 PrefRadio.prototype = { | 101 PrefRadio.prototype = { |
91 // Set up the prototype chain | 102 // Set up the prototype chain |
92 __proto__: HTMLInputElement.prototype, | 103 __proto__: HTMLInputElement.prototype, |
93 | 104 |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 PrefCheckbox: PrefCheckbox, | 424 PrefCheckbox: PrefCheckbox, |
414 PrefNumber: PrefNumber, | 425 PrefNumber: PrefNumber, |
415 PrefNumeric: PrefNumeric, | 426 PrefNumeric: PrefNumeric, |
416 PrefRadio: PrefRadio, | 427 PrefRadio: PrefRadio, |
417 PrefRange: PrefRange, | 428 PrefRange: PrefRange, |
418 PrefSelect: PrefSelect, | 429 PrefSelect: PrefSelect, |
419 PrefTextField: PrefTextField | 430 PrefTextField: PrefTextField |
420 }; | 431 }; |
421 | 432 |
422 }); | 433 }); |
OLD | NEW |