OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 /** | 9 /** |
10 * Allows an element to be disabled for several reasons. | 10 * Allows an element to be disabled for several reasons. |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 * true, the default handler is suppressed. | 117 * true, the default handler is suppressed. |
118 * @param {Event} event Input element change event. | 118 * @param {Event} event Input element change event. |
119 */ | 119 */ |
120 customPrefChangeHandler: function(event) { | 120 customPrefChangeHandler: function(event) { |
121 return false; | 121 return false; |
122 }, | 122 }, |
123 }; | 123 }; |
124 | 124 |
125 /** | 125 /** |
126 * The name of the associated preference. | 126 * The name of the associated preference. |
127 * @type {string} | |
128 */ | 127 */ |
129 cr.defineProperty(PrefInputElement, 'pref', cr.PropertyKind.ATTR); | 128 cr.defineProperty(PrefInputElement, 'pref', cr.PropertyKind.ATTR); |
130 | 129 |
131 /** | 130 /** |
132 * The data type of the associated preference, only relevant for derived | 131 * The data type of the associated preference, only relevant for derived |
133 * classes that support different data types. | 132 * classes that support different data types. |
134 * @type {string} | |
135 */ | 133 */ |
136 cr.defineProperty(PrefInputElement, 'dataType', cr.PropertyKind.ATTR); | 134 cr.defineProperty(PrefInputElement, 'dataType', cr.PropertyKind.ATTR); |
137 | 135 |
138 /** | 136 /** |
139 * Whether this input element is part of a dialog. If so, changes take effect | 137 * Whether this input element is part of a dialog. If so, changes take effect |
140 * in the settings UI immediately but are only actually committed when the | 138 * in the settings UI immediately but are only actually committed when the |
141 * user confirms the dialog. If the user cancels the dialog instead, the | 139 * user confirms the dialog. If the user cancels the dialog instead, the |
142 * changes are rolled back in the settings UI and never committed. | 140 * changes are rolled back in the settings UI and never committed. |
143 * @type {boolean} | |
144 */ | 141 */ |
145 cr.defineProperty(PrefInputElement, 'dialogPref', cr.PropertyKind.BOOL_ATTR); | 142 cr.defineProperty(PrefInputElement, 'dialogPref', cr.PropertyKind.BOOL_ATTR); |
146 | 143 |
147 /** | 144 /** |
148 * Whether the associated preference is controlled by a source other than the | 145 * Whether the associated preference is controlled by a source other than the |
149 * user's setting (can be 'policy', 'extension', 'recommended' or unset). | 146 * user's setting (can be 'policy', 'extension', 'recommended' or unset). |
150 * @type {string} | |
151 */ | 147 */ |
152 cr.defineProperty(PrefInputElement, 'controlledBy', cr.PropertyKind.ATTR); | 148 cr.defineProperty(PrefInputElement, 'controlledBy', cr.PropertyKind.ATTR); |
153 | 149 |
154 /** | 150 /** |
155 * The user metric string. | 151 * The user metric string. |
156 * @type {string} | |
157 */ | 152 */ |
158 cr.defineProperty(PrefInputElement, 'metric', cr.PropertyKind.ATTR); | 153 cr.defineProperty(PrefInputElement, 'metric', cr.PropertyKind.ATTR); |
159 | 154 |
160 ///////////////////////////////////////////////////////////////////////////// | 155 ///////////////////////////////////////////////////////////////////////////// |
161 // PrefCheckbox class: | 156 // PrefCheckbox class: |
162 | 157 |
163 // Define a constructor that uses an input element as its underlying element. | 158 // Define a constructor that uses an input element as its underlying element. |
164 var PrefCheckbox = cr.ui.define('input'); | 159 var PrefCheckbox = cr.ui.define('input'); |
165 | 160 |
166 PrefCheckbox.prototype = { | 161 PrefCheckbox.prototype = { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 updateStateFromPref_: function(event) { | 194 updateStateFromPref_: function(event) { |
200 if (this.customPrefChangeHandler(event)) | 195 if (this.customPrefChangeHandler(event)) |
201 return; | 196 return; |
202 var value = Boolean(event.value.value); | 197 var value = Boolean(event.value.value); |
203 this.checked = this.inverted_pref ? !value : value; | 198 this.checked = this.inverted_pref ? !value : value; |
204 }, | 199 }, |
205 }; | 200 }; |
206 | 201 |
207 /** | 202 /** |
208 * Whether the mapping between checkbox state and associated pref is inverted. | 203 * Whether the mapping between checkbox state and associated pref is inverted. |
209 * @type {boolean} | |
210 */ | 204 */ |
211 cr.defineProperty(PrefCheckbox, 'inverted_pref', cr.PropertyKind.BOOL_ATTR); | 205 cr.defineProperty(PrefCheckbox, 'inverted_pref', cr.PropertyKind.BOOL_ATTR); |
212 | 206 |
213 ///////////////////////////////////////////////////////////////////////////// | 207 ///////////////////////////////////////////////////////////////////////////// |
214 // PrefNumber class: | 208 // PrefNumber class: |
215 | 209 |
216 // Define a constructor that uses an input element as its underlying element. | 210 // Define a constructor that uses an input element as its underlying element. |
217 var PrefNumber = cr.ui.define('input'); | 211 var PrefNumber = cr.ui.define('input'); |
218 | 212 |
219 PrefNumber.prototype = { | 213 PrefNumber.prototype = { |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 * Update the selected item when the associated pref changes. | 406 * Update the selected item when the associated pref changes. |
413 * @param {Event} event Pref change event. | 407 * @param {Event} event Pref change event. |
414 * @private | 408 * @private |
415 */ | 409 */ |
416 updateStateFromPref_: function(event) { | 410 updateStateFromPref_: function(event) { |
417 if (this.customPrefChangeHandler(event)) | 411 if (this.customPrefChangeHandler(event)) |
418 return; | 412 return; |
419 | 413 |
420 // Make sure the value is a string, because the value is stored as a | 414 // Make sure the value is a string, because the value is stored as a |
421 // string in the HTMLOptionElement. | 415 // string in the HTMLOptionElement. |
422 value = String(event.value.value); | 416 var value = String(event.value.value); |
423 | 417 |
424 var found = false; | 418 var found = false; |
425 for (var i = 0; i < this.options.length; i++) { | 419 for (var i = 0; i < this.options.length; i++) { |
426 if (this.options[i].value == value) { | 420 if (this.options[i].value == value) { |
427 this.selectedIndex = i; | 421 this.selectedIndex = i; |
428 found = true; | 422 found = true; |
429 } | 423 } |
430 } | 424 } |
431 | 425 |
432 // Item not found, select first item. | 426 // Item not found, select first item. |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 /** | 548 /** |
555 * See |updateDisabledState_| above. | 549 * See |updateDisabledState_| above. |
556 */ | 550 */ |
557 setDisabled: function(reason, disabled) { | 551 setDisabled: function(reason, disabled) { |
558 updateDisabledState_(this, reason, disabled); | 552 updateDisabledState_(this, reason, disabled); |
559 }, | 553 }, |
560 }; | 554 }; |
561 | 555 |
562 /** | 556 /** |
563 * The name of the associated preference. | 557 * The name of the associated preference. |
564 * @type {string} | |
565 */ | 558 */ |
566 cr.defineProperty(PrefButton, 'pref', cr.PropertyKind.ATTR); | 559 cr.defineProperty(PrefButton, 'pref', cr.PropertyKind.ATTR); |
567 | 560 |
568 /** | 561 /** |
569 * Whether the associated preference is controlled by a source other than the | 562 * Whether the associated preference is controlled by a source other than the |
570 * user's setting (can be 'policy', 'extension', 'recommended' or unset). | 563 * user's setting (can be 'policy', 'extension', 'recommended' or unset). |
571 * @type {string} | |
572 */ | 564 */ |
573 cr.defineProperty(PrefButton, 'controlledBy', cr.PropertyKind.ATTR); | 565 cr.defineProperty(PrefButton, 'controlledBy', cr.PropertyKind.ATTR); |
574 | 566 |
575 // Export | 567 // Export |
576 return { | 568 return { |
577 PrefCheckbox: PrefCheckbox, | 569 PrefCheckbox: PrefCheckbox, |
578 PrefNumber: PrefNumber, | 570 PrefNumber: PrefNumber, |
579 PrefRadio: PrefRadio, | 571 PrefRadio: PrefRadio, |
580 PrefRange: PrefRange, | 572 PrefRange: PrefRange, |
581 PrefSelect: PrefSelect, | 573 PrefSelect: PrefSelect, |
582 PrefTextField: PrefTextField, | 574 PrefTextField: PrefTextField, |
583 PrefPortNumber: PrefPortNumber, | 575 PrefPortNumber: PrefPortNumber, |
584 PrefButton: PrefButton | 576 PrefButton: PrefButton |
585 }; | 577 }; |
586 | 578 |
587 }); | 579 }); |
OLD | NEW |