Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // TODO(jhawkins): Refactor all this copy-pasted code! | 10 // TODO(jhawkins): Refactor all this copy-pasted code! |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 401 if (!found) | 401 if (!found) |
| 402 self.selectedIndex = 0; | 402 self.selectedIndex = 0; |
| 403 | 403 |
| 404 if (self.onchange != undefined) | 404 if (self.onchange != undefined) |
| 405 self.onchange(event); | 405 self.onchange(event); |
| 406 }); | 406 }); |
| 407 | 407 |
| 408 // Listen to user events. | 408 // Listen to user events. |
| 409 this.addEventListener('change', | 409 this.addEventListener('change', |
| 410 function(e) { | 410 function(e) { |
| 411 if (!self.dataType) | 411 if (!self.dataType) { |
| 412 console.error('unknown data type for <select> pref'); | 412 console.error('undefined data type for <select> pref'); |
| 413 return; | |
| 414 } | |
| 413 | 415 |
| 414 switch(self.dataType) { | 416 switch(self.dataType) { |
| 415 case 'number': | 417 case 'number': |
| 416 Preferences.setIntegerPref(self.pref, | 418 Preferences.setIntegerPref(self.pref, |
| 417 self.options[self.selectedIndex].value, self.metric); | 419 self.options[self.selectedIndex].value, self.metric); |
| 418 break; | 420 break; |
| 421 case 'real': | |
| 422 Preferences.setRealPref(self.pref, | |
| 423 self.options[self.selectedIndex].value, self.metric); | |
| 424 break; | |
| 419 case 'boolean': | 425 case 'boolean': |
| 420 var option = self.options[self.selectedIndex]; | 426 var option = self.options[self.selectedIndex]; |
| 421 var value = (option.value == 'true') ? true : false; | 427 var value = (option.value == 'true') ? true : false; |
| 422 Preferences.setBooleanPref(self.pref, value, self.metric); | 428 Preferences.setBooleanPref(self.pref, value, self.metric); |
| 423 break; | 429 break; |
| 424 case 'string': | 430 case 'string': |
| 425 case undefined: // Assume the pref is a string. | |
| 426 Preferences.setStringPref(self.pref, | 431 Preferences.setStringPref(self.pref, |
| 427 self.options[self.selectedIndex].value, self.metric); | 432 self.options[self.selectedIndex].value, self.metric); |
| 428 break; | 433 break; |
| 434 default: | |
| 435 console.error('unknown data type for <select> pref: ' + | |
| 436 self.dataType); | |
| 429 } | 437 } |
| 430 }); | 438 }); |
| 431 }, | 439 }, |
| 440 | |
| 441 /** | |
| 442 * Getter for preference data type attribute. | |
| 443 */ | |
| 444 get dataType() { | |
| 445 return this.getAttribute('dataType'); | |
| 446 }, | |
| 447 /** | |
| 448 * Setter for preference data type attribute. | |
| 449 */ | |
|
stuartmorgan
2011/01/12 22:59:41
The code I've seen doesn't have separate docs for
Evan Stade
2011/01/12 23:19:20
i copied this style from within this same file.
| |
| 450 set dataType(name) { | |
| 451 this.setAttribute('dataType', name); | |
| 452 } | |
| 432 }; | 453 }; |
| 433 | 454 |
| 434 /** | 455 /** |
| 435 * The preference name. | 456 * The preference name. |
| 436 * @type {string} | 457 * @type {string} |
| 437 */ | 458 */ |
| 438 cr.defineProperty(PrefSelect, 'pref', cr.PropertyKind.ATTR); | 459 cr.defineProperty(PrefSelect, 'pref', cr.PropertyKind.ATTR); |
| 439 | 460 |
| 440 /** | 461 /** |
| 441 * The user metric string. | 462 * The user metric string. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 505 PrefCheckbox: PrefCheckbox, | 526 PrefCheckbox: PrefCheckbox, |
| 506 PrefNumber: PrefNumber, | 527 PrefNumber: PrefNumber, |
| 507 PrefNumeric: PrefNumeric, | 528 PrefNumeric: PrefNumeric, |
| 508 PrefRadio: PrefRadio, | 529 PrefRadio: PrefRadio, |
| 509 PrefRange: PrefRange, | 530 PrefRange: PrefRange, |
| 510 PrefSelect: PrefSelect, | 531 PrefSelect: PrefSelect, |
| 511 PrefTextField: PrefTextField | 532 PrefTextField: PrefTextField |
| 512 }; | 533 }; |
| 513 | 534 |
| 514 }); | 535 }); |
| OLD | NEW |