OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 cr.define('options', function() { |
| 6 |
| 7 ///////////////////////////////////////////////////////////////////////////// |
| 8 // MinimumFontSizeSelect class: |
| 9 |
| 10 // Define a constructor that uses a select element as its underlying element. |
| 11 var MinimumFontSizeSelect = cr.ui.define('select'); |
| 12 |
| 13 MinimumFontSizeSelect.prototype = { |
| 14 // Set up the prototype chain |
| 15 __proto__: HTMLSelectElement.prototype, |
| 16 |
| 17 /** |
| 18 * Initialization function for the cr.ui framework. |
| 19 */ |
| 20 decorate: function() { |
| 21 var self = this; |
| 22 |
| 23 // Listen to pref changes. |
| 24 Preferences.getInstance().addEventListener( |
| 25 'webkit.webprefs.minimum_font_size', function(event) { |
| 26 var value = (event.value && event.value['value'] != undefined) |
| 27 ? event.value['value'] : event.value; |
| 28 self.managed = (event.value && event.value['managed'] != undefined) |
| 29 ? event.value['managed'] : false; |
| 30 self.disabled = self.managed; |
| 31 for (var i = 0; i < self.options.length; i++) { |
| 32 if (self.options[i].value == value) { |
| 33 self.selectedIndex = i; |
| 34 return; |
| 35 } |
| 36 } |
| 37 // Item not found, select first item. |
| 38 self.selectedIndex = 0; |
| 39 }); |
| 40 |
| 41 // Listen to user events. |
| 42 this.addEventListener('change', |
| 43 function(e) { |
| 44 if (self.options[self.selectedIndex].value > 0) { |
| 45 Preferences.setIntegerPref( |
| 46 'webkit.webprefs.minimum_font_size', |
| 47 self.options[self.selectedIndex].value, |
| 48 'Options_ChangeMinimumFontSize'); |
| 49 Preferences.setIntegerPref( |
| 50 'webkit.webprefs.minimum_logical_font_size', |
| 51 self.options[self.selectedIndex].value, ''); |
| 52 } else { |
| 53 Preferences.clearPref( |
| 54 'webkit.webprefs.minimum_font_size', |
| 55 'Options_ChangeMinimumFontSize'); |
| 56 Preferences.clearPref( |
| 57 'webkit.webprefs.minimum_logical_font_size', ''); |
| 58 } |
| 59 }); |
| 60 }, |
| 61 |
| 62 /** |
| 63 * Sets up options in select element. |
| 64 * @param {Array} options List of option and their display text. |
| 65 * Each element in the array is an array of length 2 which contains options |
| 66 * value in the first element and display text in the second element. |
| 67 * |
| 68 * TODO(zelidrag): move this to that i18n template classes. |
| 69 */ |
| 70 initializeValues: function(options) { |
| 71 options.forEach(function(values) { |
| 72 this.appendChild(new Option(values[1], values[0])); |
| 73 }, this); |
| 74 } |
| 75 }; |
| 76 |
| 77 // Export |
| 78 return { |
| 79 MinimumFontSizeSelect: MinimumFontSizeSelect |
| 80 }; |
| 81 |
| 82 }); |
| 83 |
OLD | NEW |