| 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 // TODO(jhawkins): Refactor all this copy-pasted code! | 10 // TODO(jhawkins): Refactor all this copy-pasted code! |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 PrefSelect.prototype = { | 286 PrefSelect.prototype = { |
| 287 // Set up the prototype chain | 287 // Set up the prototype chain |
| 288 __proto__: HTMLSelectElement.prototype, | 288 __proto__: HTMLSelectElement.prototype, |
| 289 | 289 |
| 290 /** | 290 /** |
| 291 * Initialization function for the cr.ui framework. | 291 * Initialization function for the cr.ui framework. |
| 292 */ | 292 */ |
| 293 decorate: function() { | 293 decorate: function() { |
| 294 var self = this; | 294 var self = this; |
| 295 | 295 |
| 296 var values = self.getAttribute('data-values'); | |
| 297 if (values) { | |
| 298 self.initializeValues(templateData[values]); | |
| 299 } | |
| 300 | |
| 301 // Listen to pref changes. | 296 // Listen to pref changes. |
| 302 Preferences.getInstance().addEventListener(this.pref, | 297 Preferences.getInstance().addEventListener(this.pref, |
| 303 function(event) { | 298 function(event) { |
| 304 var value = event.value && event.value['value'] != undefined ? | 299 var value = event.value && event.value['value'] != undefined ? |
| 305 event.value['value'] : event.value; | 300 event.value['value'] : event.value; |
| 306 | 301 |
| 307 // Make sure |value| is a string, because the value is stored as a | 302 // Make sure |value| is a string, because the value is stored as a |
| 308 // string in the HTMLOptionElement. | 303 // string in the HTMLOptionElement. |
| 309 value = value.toString(); | 304 value = value.toString(); |
| 310 | 305 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 var value = (option.value == 'true') ? true : false; | 341 var value = (option.value == 'true') ? true : false; |
| 347 Preferences.setBooleanPref(self.pref, value, self.metric); | 342 Preferences.setBooleanPref(self.pref, value, self.metric); |
| 348 break; | 343 break; |
| 349 case 'string': | 344 case 'string': |
| 350 Preferences.setStringPref(self.pref, | 345 Preferences.setStringPref(self.pref, |
| 351 self.options[self.selectedIndex].value, self.metric); | 346 self.options[self.selectedIndex].value, self.metric); |
| 352 break; | 347 break; |
| 353 } | 348 } |
| 354 }); | 349 }); |
| 355 }, | 350 }, |
| 356 | |
| 357 /** | |
| 358 * Sets up options in select element. | |
| 359 * @param {Array} options List of option and their display text. | |
| 360 * Each element in the array is an array of length 2 which contains | |
| 361 * options value in the first element and display text in the second | |
| 362 * element. May be undefined. | |
| 363 * | |
| 364 * TODO(zelidrag): move this to that i18n template classes. | |
| 365 */ | |
| 366 initializeValues: function(options) { | |
| 367 options.forEach(function (values) { | |
| 368 if (this.dataType == undefined) | |
| 369 this.dataType = typeof values[0]; | |
| 370 | |
| 371 this.appendChild(new Option(values[1], values[0])); | |
| 372 }, this); | |
| 373 } | |
| 374 }; | 351 }; |
| 375 | 352 |
| 376 /** | 353 /** |
| 377 * The preference name. | 354 * The preference name. |
| 378 * @type {string} | 355 * @type {string} |
| 379 */ | 356 */ |
| 380 cr.defineProperty(PrefSelect, 'pref', cr.PropertyKind.ATTR); | 357 cr.defineProperty(PrefSelect, 'pref', cr.PropertyKind.ATTR); |
| 381 | 358 |
| 382 /** | 359 /** |
| 383 * The user metric string. | 360 * The user metric string. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 PrefCheckbox: PrefCheckbox, | 424 PrefCheckbox: PrefCheckbox, |
| 448 PrefNumber: PrefNumber, | 425 PrefNumber: PrefNumber, |
| 449 PrefNumeric: PrefNumeric, | 426 PrefNumeric: PrefNumeric, |
| 450 PrefRadio: PrefRadio, | 427 PrefRadio: PrefRadio, |
| 451 PrefRange: PrefRange, | 428 PrefRange: PrefRange, |
| 452 PrefSelect: PrefSelect, | 429 PrefSelect: PrefSelect, |
| 453 PrefTextField: PrefTextField | 430 PrefTextField: PrefTextField |
| 454 }; | 431 }; |
| 455 | 432 |
| 456 }); | 433 }); |
| OLD | NEW |