2 * Copyright (C) 2014 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 WebInspector.SettingsUI = {}
34 * @param {string} name
35 * @param {!WebInspector.Setting} setting
36 * @param {boolean=} omitParagraphElement
37 * @param {!Element=} inputElement
38 * @param {string=} tooltip
41 WebInspector.SettingsUI.createSettingCheckbox = function(name, setting, omitParagraphElement, inputElement, tooltip)
43 var input = inputElement || document.createElement("input");
44 input.type = "checkbox";
46 WebInspector.SettingsUI.bindCheckbox(input, setting);
48 var label = document.createElement("label");
49 label.appendChild(input);
50 label.createTextChild(name);
52 label.title = tooltip;
54 if (omitParagraphElement)
57 var p = document.createElement("p");
63 * @param {!Element} input
64 * @param {!WebInspector.Setting} setting
66 WebInspector.SettingsUI.bindCheckbox = function(input, setting)
68 function settingChanged()
70 if (input.checked !== setting.get())
71 input.checked = setting.get();
73 setting.addChangeListener(settingChanged);
76 function inputChanged()
78 if (setting.get() !== input.checked)
79 setting.set(input.checked);
81 input.addEventListener("change", inputChanged, false);
85 * @param {string} label
86 * @param {!WebInspector.Setting} setting
87 * @param {boolean} numeric
88 * @param {number=} maxLength
89 * @param {string=} width
90 * @param {function(string):?string=} validatorCallback
92 WebInspector.SettingsUI.createSettingInputField = function(label, setting, numeric, maxLength, width, validatorCallback)
94 var p = document.createElement("p");
95 var labelElement = p.createChild("label");
96 labelElement.textContent = label;
97 var inputElement = p.createChild("input");
98 inputElement.value = setting.get();
99 inputElement.type = "text";
101 inputElement.className = "numeric";
103 inputElement.maxLength = maxLength;
105 inputElement.style.width = width;
107 var errorMessageLabel;
108 if (validatorCallback) {
109 errorMessageLabel = p.createChild("div");
110 errorMessageLabel.classList.add("field-error-message");
111 inputElement.oninput = onInput;
117 var error = validatorCallback(inputElement.value);
120 errorMessageLabel.textContent = error;
125 setting.set(numeric ? Number(inputElement.value) : inputElement.value);
127 inputElement.addEventListener("blur", onBlur, false);
132 WebInspector.SettingsUI.createCustomSetting = function(name, element)
134 var p = document.createElement("p");
135 var fieldsetElement = document.createElement("fieldset");
136 fieldsetElement.createChild("label").textContent = name;
137 fieldsetElement.appendChild(element);
138 p.appendChild(fieldsetElement);
143 * @param {!WebInspector.Setting} setting
146 WebInspector.SettingsUI.createSettingFieldset = function(setting)
148 var fieldset = document.createElement("fieldset");
149 fieldset.disabled = !setting.get();
150 setting.addChangeListener(settingChanged);
153 function settingChanged()
155 fieldset.disabled = !setting.get();
160 * @param {string} text
163 WebInspector.SettingsUI.regexValidator = function(text)
167 regex = new RegExp(text);
170 return regex ? null : WebInspector.UIString("Invalid pattern");
176 WebInspector.UISettingDelegate = function()
180 WebInspector.UISettingDelegate.prototype = {
184 settingElement: function()