Chromium Code Reviews| Index: Source/devtools/front_end/ui/SettingsUI.js |
| diff --git a/Source/devtools/front_end/ui/SettingsUI.js b/Source/devtools/front_end/ui/SettingsUI.js |
| index 967b80f7961636aac9028e70a2ff1d0124997f68..cafb3a2749dc1d1b7166e23f0804acd15cf0f1cf 100644 |
| --- a/Source/devtools/front_end/ui/SettingsUI.js |
| +++ b/Source/devtools/front_end/ui/SettingsUI.js |
| @@ -88,8 +88,9 @@ WebInspector.SettingsUI.bindCheckbox = function(input, setting) |
| * @param {number=} maxLength |
| * @param {string=} width |
| * @param {function(string):?string=} validatorCallback |
| + * @param {boolean=} instant |
| */ |
| -WebInspector.SettingsUI.createSettingInputField = function(label, setting, numeric, maxLength, width, validatorCallback) |
| +WebInspector.SettingsUI.createSettingInputField = function(label, setting, numeric, maxLength, width, validatorCallback, instant) |
| { |
| var p = document.createElement("p"); |
| var labelElement = p.createChild("label"); |
| @@ -104,27 +105,50 @@ WebInspector.SettingsUI.createSettingInputField = function(label, setting, numer |
| if (width) |
| inputElement.style.width = width; |
| + if (validatorCallback || instant) { |
| + inputElement.addEventListener("change", onInput, false); |
| + inputElement.addEventListener("input", onInput, false); |
| + } |
| + |
| var errorMessageLabel; |
| if (validatorCallback) { |
| errorMessageLabel = p.createChild("div"); |
| errorMessageLabel.classList.add("field-error-message"); |
| - inputElement.oninput = onInput; |
| - onInput(); |
| + validate(); |
| } |
| function onInput() |
| { |
| + if (validatorCallback) |
| + validate(); |
| + if (instant) |
| + apply(); |
|
dgozman
2014/05/28 09:39:10
Why apply if validation failed?
pfeldman
2014/05/28 15:07:45
Done.
|
| + } |
| + |
| + function validate() |
| + { |
| var error = validatorCallback(inputElement.value); |
| if (!error) |
| error = ""; |
| errorMessageLabel.textContent = error; |
| } |
| - function onBlur() |
| + if (!instant) |
| + inputElement.addEventListener("blur", apply, false); |
| + |
| + function apply() |
| { |
| + setting.removeChangeListener(onSettingChange); |
| setting.set(numeric ? Number(inputElement.value) : inputElement.value); |
| + setting.addChangeListener(onSettingChange); |
| + } |
| + |
| + setting.addChangeListener(onSettingChange); |
| + |
| + function onSettingChange() |
| + { |
| + inputElement.value = setting.get(); |
| } |
| - inputElement.addEventListener("blur", onBlur, false); |
| return p; |
| } |
| @@ -202,26 +226,6 @@ WebInspector.SettingsUI.createInput = function(parentElement, id, defaultText, e |
| } |
| /** |
| - * @param {string} title |
| - * @param {function(boolean)} callback |
| - */ |
| -WebInspector.SettingsUI.createNonPersistedCheckbox = function(title, callback) |
| -{ |
| - var labelElement = document.createElement("label"); |
| - var checkboxElement = labelElement.createChild("input"); |
| - checkboxElement.type = "checkbox"; |
| - checkboxElement.checked = false; |
| - checkboxElement.addEventListener("click", onclick, false); |
| - labelElement.appendChild(document.createTextNode(title)); |
| - return labelElement; |
| - |
| - function onclick() |
| - { |
| - callback(checkboxElement.checked); |
| - } |
| -} |
| - |
| -/** |
| * @constructor |
| */ |
| WebInspector.UISettingDelegate = function() |