Chromium Code Reviews| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 * @param {!Element=} inputElement | 73 * @param {!Element=} inputElement |
| 74 * @param {string=} tooltip | 74 * @param {string=} tooltip |
| 75 * @return {!Element} | 75 * @return {!Element} |
| 76 */ | 76 */ |
| 77 WebInspector.SettingsUI.createSettingCheckbox = function(name, setting, omitPara graphElement, inputElement, tooltip) | 77 WebInspector.SettingsUI.createSettingCheckbox = function(name, setting, omitPara graphElement, inputElement, tooltip) |
| 78 { | 78 { |
| 79 return WebInspector.SettingsUI.createCheckbox(name, setting.get.bind(setting ), setting.set.bind(setting), omitParagraphElement, inputElement, tooltip); | 79 return WebInspector.SettingsUI.createCheckbox(name, setting.get.bind(setting ), setting.set.bind(setting), omitParagraphElement, inputElement, tooltip); |
| 80 } | 80 } |
| 81 | 81 |
| 82 /** | 82 /** |
| 83 * @param {string} label | |
| 84 * @param {!WebInspector.Setting} setting | |
| 85 * @param {boolean} numeric | |
| 86 * @param {number=} maxLength | |
| 87 * @param {string=} width | |
| 88 * @param {function(string):?string=} validatorCallback | |
| 89 */ | |
| 90 WebInspector.SettingsUI.createSettingInputField = function(label, setting, numer ic, maxLength, width, validatorCallback) | |
| 91 { | |
| 92 var p = document.createElement("p"); | |
| 93 var labelElement = p.createChild("label"); | |
| 94 labelElement.textContent = label; | |
| 95 var inputElement = p.createChild("input"); | |
| 96 inputElement.value = setting.get(); | |
| 97 inputElement.type = "text"; | |
| 98 if (numeric) | |
| 99 inputElement.className = "numeric"; | |
| 100 if (maxLength) | |
| 101 inputElement.maxLength = maxLength; | |
| 102 if (width) | |
| 103 inputElement.style.width = width; | |
| 104 | |
| 105 var errorMessageLabel; | |
| 106 if (validatorCallback) { | |
| 107 errorMessageLabel = p.createChild("div"); | |
| 108 errorMessageLabel.classList.add("field-error-message"); | |
| 109 inputElement.oninput = onInput; | |
| 110 onInput(); | |
| 111 } | |
| 112 | |
| 113 function onInput() | |
| 114 { | |
| 115 var error = validatorCallback(inputElement.value); | |
| 116 if (!error) | |
| 117 error = ""; | |
| 118 errorMessageLabel.textContent = error; | |
| 119 } | |
| 120 | |
| 121 function onBlur() | |
| 122 { | |
| 123 setting.set(numeric ? Number(inputElement.value) : inputElement.value); | |
| 124 } | |
| 125 inputElement.addEventListener("blur", onBlur, false); | |
| 126 | |
| 127 return p; | |
| 128 } | |
| 129 | |
| 130 WebInspector.SettingsUI.createCustomSetting = function(name, element) | |
| 131 { | |
| 132 var p = document.createElement("p"); | |
| 133 var fieldsetElement = document.createElement("fieldset"); | |
| 134 fieldsetElement.createChild("label").textContent = name; | |
| 135 fieldsetElement.appendChild(element); | |
| 136 p.appendChild(fieldsetElement); | |
| 137 return p; | |
| 138 } | |
| 139 | |
| 140 /** | |
| 83 * @param {!WebInspector.Setting} setting | 141 * @param {!WebInspector.Setting} setting |
| 84 * @return {!Element} | 142 * @return {!Element} |
| 85 */ | 143 */ |
| 86 WebInspector.SettingsUI.createSettingFieldset = function(setting) | 144 WebInspector.SettingsUI.createSettingFieldset = function(setting) |
| 87 { | 145 { |
| 88 var fieldset = document.createElement("fieldset"); | 146 var fieldset = document.createElement("fieldset"); |
| 89 fieldset.disabled = !setting.get(); | 147 fieldset.disabled = !setting.get(); |
| 90 setting.addChangeListener(settingChanged); | 148 setting.addChangeListener(settingChanged); |
| 91 return fieldset; | 149 return fieldset; |
| 92 | 150 |
| 93 function settingChanged() | 151 function settingChanged() |
| 94 { | 152 { |
| 95 fieldset.disabled = !setting.get(); | 153 fieldset.disabled = !setting.get(); |
| 96 } | 154 } |
| 97 } | 155 } |
| 156 | |
| 157 /** | |
| 158 * @param {string} text | |
| 159 * @return {?string} | |
| 160 */ | |
| 161 WebInspector.SettingsUI.regexValidator = function(text) | |
| 162 { | |
| 163 var regex; | |
| 164 try { | |
| 165 regex = new RegExp(text); | |
| 166 } catch (e) { | |
| 167 } | |
| 168 return regex ? null : WebInspector.UIString("Invalid pattern"); | |
| 169 } | |
| 170 | |
| 171 /** | |
| 172 * @constructor | |
| 173 */ | |
| 174 WebInspector.UISettingDelegate = function() | |
| 175 { | |
| 176 } | |
| 177 | |
| 178 WebInspector.UISettingDelegate.prototype = { | |
| 179 /** | |
| 180 * @return {?Element} | |
| 181 */ | |
| 182 settingElement: function() | |
| 183 { | |
| 184 return null; | |
| 185 }, | |
| 186 | |
| 187 /** | |
| 188 * @param {!WebInspector.Event} event | |
| 189 */ | |
| 190 settingChanged: function(event) | |
|
pfeldman
2014/03/31 12:00:43
Lets make UISettingDelegate setting-less.
apavlov
2014/04/01 10:34:56
Done.
| |
| 191 { | |
| 192 } | |
| 193 } | |
| OLD | NEW |