OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 if (omitParagraphElement) | 48 if (omitParagraphElement) |
49 return label; | 49 return label; |
50 | 50 |
51 var p = createElement('p'); | 51 var p = createElement('p'); |
52 p.appendChild(label); | 52 p.appendChild(label); |
53 return p; | 53 return p; |
54 }; | 54 }; |
55 | 55 |
56 /** | 56 /** |
| 57 * @param {string} name |
| 58 * @param {!Array<!{text: string, value: *, raw: (boolean|undefined)}>} options |
| 59 * @param {!Common.Setting} setting |
| 60 * @return {!Element} |
| 61 */ |
| 62 UI.SettingsUI.createSettingSelect = function(name, options, setting) { |
| 63 var p = createElement('p'); |
| 64 p.createChild('label').textContent = name; |
| 65 var select = p.createChild('select', 'chrome-select'); |
| 66 |
| 67 for (var i = 0; i < options.length; ++i) { |
| 68 // The "raw" flag indicates text is non-i18n-izable. |
| 69 var option = options[i]; |
| 70 var optionName = option.raw ? option.text : Common.UIString(option.text); |
| 71 select.add(new Option(optionName, option.value)); |
| 72 } |
| 73 |
| 74 setting.addChangeListener(settingChanged); |
| 75 settingChanged(); |
| 76 select.addEventListener('change', selectChanged, false); |
| 77 return p; |
| 78 |
| 79 function settingChanged() { |
| 80 var newValue = setting.get(); |
| 81 for (var i = 0; i < options.length; i++) { |
| 82 if (options[i].value === newValue) |
| 83 select.selectedIndex = i; |
| 84 } |
| 85 } |
| 86 |
| 87 function selectChanged() { |
| 88 // Don't use event.target.value to avoid conversion of the value to string. |
| 89 setting.set(options[select.selectedIndex].value); |
| 90 } |
| 91 }; |
| 92 |
| 93 /** |
57 * @param {!Element} input | 94 * @param {!Element} input |
58 * @param {!Common.Setting} setting | 95 * @param {!Common.Setting} setting |
59 */ | 96 */ |
60 UI.SettingsUI.bindCheckbox = function(input, setting) { | 97 UI.SettingsUI.bindCheckbox = function(input, setting) { |
61 function settingChanged() { | 98 function settingChanged() { |
62 if (input.checked !== setting.get()) | 99 if (input.checked !== setting.get()) |
63 input.checked = setting.get(); | 100 input.checked = setting.get(); |
64 } | 101 } |
65 setting.addChangeListener(settingChanged); | 102 setting.addChangeListener(settingChanged); |
66 settingChanged(); | 103 settingChanged(); |
(...skipping 22 matching lines...) Expand all Loading... |
89 * @interface | 126 * @interface |
90 */ | 127 */ |
91 UI.SettingUI = function() {}; | 128 UI.SettingUI = function() {}; |
92 | 129 |
93 UI.SettingUI.prototype = { | 130 UI.SettingUI.prototype = { |
94 /** | 131 /** |
95 * @return {?Element} | 132 * @return {?Element} |
96 */ | 133 */ |
97 settingElement() {} | 134 settingElement() {} |
98 }; | 135 }; |
OLD | NEW |