Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2044)

Unified Diff: Source/devtools/front_end/ui/SettingsUI.js

Issue 304693002: DevTools: get rid of deviceMetics settings. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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()

Powered by Google App Engine
This is Rietveld 408576698