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<!Runtime.ExtensionDescriptor.Option>} options | |
59 * @param {!Common.Setting} setting | |
60 * @return {!Element} | |
61 */ | |
62 UI.SettingsUI.createSettingSelect = function(name, options, setting) { | |
pfeldman
2017/05/10 20:58:42
Oh, this is a good one!
luoe
2017/05/11 21:39:43
XD
| |
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 = /** @type {!Runtime.ExtensionDescriptor.Option} */ (options[i]) ; | |
70 var optionText = /** @type {string} */ (option.text); | |
71 var optionName = option.raw ? optionText : Common.UIString(optionText); | |
72 select.add(new Option(optionName, option.value)); | |
73 } | |
74 | |
75 setting.addChangeListener(settingChanged); | |
76 settingChanged(); | |
77 select.addEventListener('change', selectChanged, false); | |
78 return p; | |
79 | |
80 function settingChanged() { | |
81 var newValue = setting.get(); | |
82 if (options[select.selectedIndex].value !== newValue) { | |
pfeldman
2017/05/10 20:58:42
Why did you add this line? I don't think it makes
luoe
2017/05/11 21:39:43
Done.
| |
83 for (var i = 0; i < options.length; i++) { | |
84 if (options[i].value === newValue) | |
85 select.selectedIndex = i; | |
86 } | |
87 } | |
88 } | |
89 | |
90 function selectChanged() { | |
91 // Don't use event.target.value to avoid conversion of the value to string. | |
92 setting.set(options[select.selectedIndex].value); | |
93 } | |
94 }; | |
95 | |
96 /** | |
57 * @param {!Element} input | 97 * @param {!Element} input |
58 * @param {!Common.Setting} setting | 98 * @param {!Common.Setting} setting |
59 */ | 99 */ |
60 UI.SettingsUI.bindCheckbox = function(input, setting) { | 100 UI.SettingsUI.bindCheckbox = function(input, setting) { |
61 function settingChanged() { | 101 function settingChanged() { |
62 if (input.checked !== setting.get()) | 102 if (input.checked !== setting.get()) |
63 input.checked = setting.get(); | 103 input.checked = setting.get(); |
64 } | 104 } |
65 setting.addChangeListener(settingChanged); | 105 setting.addChangeListener(settingChanged); |
66 settingChanged(); | 106 settingChanged(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 * @interface | 144 * @interface |
105 */ | 145 */ |
106 UI.SettingUI = function() {}; | 146 UI.SettingUI = function() {}; |
107 | 147 |
108 UI.SettingUI.prototype = { | 148 UI.SettingUI.prototype = { |
109 /** | 149 /** |
110 * @return {?Element} | 150 * @return {?Element} |
111 */ | 151 */ |
112 settingElement() {} | 152 settingElement() {} |
113 }; | 153 }; |
OLD | NEW |