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 |
11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
13 * distribution. | 13 * distribution. |
14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
17 * | 17 * |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | |
31 WebInspector.SettingsUI = {}; | 30 WebInspector.SettingsUI = {}; |
32 | 31 |
33 /** | 32 /** |
34 * @param {string} name | 33 * @param {string} name |
35 * @param {!WebInspector.Setting} setting | 34 * @param {!WebInspector.Setting} setting |
36 * @param {boolean=} omitParagraphElement | 35 * @param {boolean=} omitParagraphElement |
37 * @param {string=} tooltip | 36 * @param {string=} tooltip |
38 * @return {!Element} | 37 * @return {!Element} |
39 */ | 38 */ |
40 WebInspector.SettingsUI.createSettingCheckbox = function(name, setting, omitPara
graphElement, tooltip) | 39 WebInspector.SettingsUI.createSettingCheckbox = function(name, setting, omitPara
graphElement, tooltip) { |
41 { | 40 var label = createCheckboxLabel(name); |
42 var label = createCheckboxLabel(name); | 41 if (tooltip) |
43 if (tooltip) | 42 label.title = tooltip; |
44 label.title = tooltip; | |
45 | 43 |
46 var input = label.checkboxElement; | 44 var input = label.checkboxElement; |
47 input.name = name; | 45 input.name = name; |
48 WebInspector.SettingsUI.bindCheckbox(input, setting); | 46 WebInspector.SettingsUI.bindCheckbox(input, setting); |
49 | 47 |
50 if (omitParagraphElement) | 48 if (omitParagraphElement) |
51 return label; | 49 return label; |
52 | 50 |
53 var p = createElement("p"); | 51 var p = createElement('p'); |
54 p.appendChild(label); | 52 p.appendChild(label); |
55 return p; | 53 return p; |
56 }; | 54 }; |
57 | 55 |
58 /** | 56 /** |
59 * @param {!Element} input | 57 * @param {!Element} input |
60 * @param {!WebInspector.Setting} setting | 58 * @param {!WebInspector.Setting} setting |
61 */ | 59 */ |
62 WebInspector.SettingsUI.bindCheckbox = function(input, setting) | 60 WebInspector.SettingsUI.bindCheckbox = function(input, setting) { |
63 { | 61 function settingChanged() { |
64 function settingChanged() | 62 if (input.checked !== setting.get()) |
65 { | 63 input.checked = setting.get(); |
66 if (input.checked !== setting.get()) | 64 } |
67 input.checked = setting.get(); | 65 setting.addChangeListener(settingChanged); |
68 } | 66 settingChanged(); |
69 setting.addChangeListener(settingChanged); | |
70 settingChanged(); | |
71 | 67 |
72 function inputChanged() | 68 function inputChanged() { |
73 { | 69 if (setting.get() !== input.checked) |
74 if (setting.get() !== input.checked) | 70 setting.set(input.checked); |
75 setting.set(input.checked); | 71 } |
76 } | 72 input.addEventListener('change', inputChanged, false); |
77 input.addEventListener("change", inputChanged, false); | |
78 }; | 73 }; |
79 | 74 |
80 /** | 75 /** |
81 * @param {string} name | 76 * @param {string} name |
82 * @param {!Element} element | 77 * @param {!Element} element |
83 * @return {!Element} | 78 * @return {!Element} |
84 */ | 79 */ |
85 WebInspector.SettingsUI.createCustomSetting = function(name, element) | 80 WebInspector.SettingsUI.createCustomSetting = function(name, element) { |
86 { | 81 var p = createElement('p'); |
87 var p = createElement("p"); | 82 var fieldsetElement = p.createChild('fieldset'); |
88 var fieldsetElement = p.createChild("fieldset"); | 83 fieldsetElement.createChild('label').textContent = name; |
89 fieldsetElement.createChild("label").textContent = name; | 84 fieldsetElement.appendChild(element); |
90 fieldsetElement.appendChild(element); | 85 return p; |
91 return p; | |
92 }; | 86 }; |
93 | 87 |
94 /** | 88 /** |
95 * @param {!WebInspector.Setting} setting | 89 * @param {!WebInspector.Setting} setting |
96 * @return {!Element} | 90 * @return {!Element} |
97 */ | 91 */ |
98 WebInspector.SettingsUI.createSettingFieldset = function(setting) | 92 WebInspector.SettingsUI.createSettingFieldset = function(setting) { |
99 { | 93 var fieldset = createElement('fieldset'); |
100 var fieldset = createElement("fieldset"); | 94 fieldset.disabled = !setting.get(); |
| 95 setting.addChangeListener(settingChanged); |
| 96 return fieldset; |
| 97 |
| 98 function settingChanged() { |
101 fieldset.disabled = !setting.get(); | 99 fieldset.disabled = !setting.get(); |
102 setting.addChangeListener(settingChanged); | 100 } |
103 return fieldset; | |
104 | |
105 function settingChanged() | |
106 { | |
107 fieldset.disabled = !setting.get(); | |
108 } | |
109 }; | 101 }; |
110 | 102 |
111 /** | 103 /** |
112 * @interface | 104 * @interface |
113 */ | 105 */ |
114 WebInspector.SettingUI = function() | 106 WebInspector.SettingUI = function() {}; |
115 { | |
116 }; | |
117 | 107 |
118 WebInspector.SettingUI.prototype = { | 108 WebInspector.SettingUI.prototype = { |
119 /** | 109 /** |
120 * @return {?Element} | 110 * @return {?Element} |
121 */ | 111 */ |
122 settingElement: function() { } | 112 settingElement: function() {} |
123 }; | 113 }; |
OLD | NEW |