OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Redefine '$' here rather than including 'cr.js', since this is | 5 // Redefine '$' here rather than including 'cr.js', since this is |
6 // the only function needed. This allows this file to be loaded | 6 // the only function needed. This allows this file to be loaded |
7 // in a browser directly for layout and some testing purposes. | 7 // in a browser directly for layout and some testing purposes. |
8 var $ = function(id) { return document.getElementById(id); }; | 8 var $ = function(id) { return document.getElementById(id); }; |
9 | 9 |
10 /** | 10 /** |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 if ($(prefName).type == 'checkbox') | 114 if ($(prefName).type == 'checkbox') |
115 value = $(prefName).checked; | 115 value = $(prefName).checked; |
116 else if ($(prefName).type == 'number') | 116 else if ($(prefName).type == 'number') |
117 value = parseFloat($(prefName).value); | 117 value = parseFloat($(prefName).value); |
118 else | 118 else |
119 value = $(prefName).value; | 119 value = $(prefName).value; |
120 chrome.send('setPreferenceValue', [prefName, value]); | 120 chrome.send('setPreferenceValue', [prefName, value]); |
121 } | 121 } |
122 | 122 |
123 /** | 123 /** |
124 * Handle processing of "Reset" button. | |
125 * Causes off form values to be updated based on current preference values. | |
126 */ | |
127 function onReset() { | |
128 for (var i = 0; i < FIELDS.length; i++) { | |
129 var field = FIELDS[i]; | |
130 if ($(field.key).type == 'checkbox') | |
131 $(field.key).checked = field.default; | |
132 else | |
133 $(field.key).value = field.default; | |
134 setPreferenceValue(field.key); | |
135 } | |
136 return false; | |
137 } | |
138 | |
139 /** | |
140 * Saves data back into Chrome preferences. | 124 * Saves data back into Chrome preferences. |
141 */ | 125 */ |
142 function onSave() { | 126 function onSave() { |
143 for (var i = 0; i < FIELDS.length; i++) { | 127 for (var i = 0; i < FIELDS.length; i++) { |
144 var field = FIELDS[i]; | 128 var field = FIELDS[i]; |
145 setPreferenceValue(field.key); | 129 setPreferenceValue(field.key); |
146 } | 130 } |
147 return false; | 131 return false; |
148 } | 132 } |
149 | 133 |
(...skipping 13 matching lines...) Expand all Loading... |
163 for (var i = 0; i < info.entries.length; ++i) { | 147 for (var i = 0; i < info.entries.length; ++i) { |
164 var entry = info.entries[i]; | 148 var entry = info.entries[i]; |
165 var row = createElementWithClass('p', 'debug'); | 149 var row = createElementWithClass('p', 'debug'); |
166 row.appendChild(createElementWithClass('span', 'timestamp')).textContent = | 150 row.appendChild(createElementWithClass('span', 'timestamp')).textContent = |
167 entry.time; | 151 entry.time; |
168 row.appendChild(document.createElement('span')).textContent = entry.text; | 152 row.appendChild(document.createElement('span')).textContent = entry.text; |
169 $('instant-debug-info').appendChild(row); | 153 $('instant-debug-info').appendChild(row); |
170 } | 154 } |
171 } | 155 } |
172 | 156 |
| 157 /** |
| 158 * Resets list of debug events. |
| 159 */ |
| 160 function clearDebugInfo() { |
| 161 $('instant-debug-info').innerHTML = ''; |
| 162 chrome.send('clearDebugInfo'); |
| 163 } |
| 164 |
173 function loadForm() { | 165 function loadForm() { |
174 for (var i = 0; i < FIELDS.length; i++) | 166 for (var i = 0; i < FIELDS.length; i++) |
175 getPreferenceValue(FIELDS[i].key); | 167 getPreferenceValue(FIELDS[i].key); |
176 } | 168 } |
177 | 169 |
178 /** | 170 /** |
179 * Build and initialize the configuration form. | 171 * Build and initialize the configuration form. |
180 */ | 172 */ |
181 function initialize() { | 173 function initialize() { |
182 buildForm(); | 174 buildForm(); |
183 loadForm(); | 175 loadForm(); |
184 initForm(); | 176 initForm(); |
185 getDebugInfo(); | 177 getDebugInfo(); |
186 | 178 |
187 $('reset-button').onclick = onReset.bind(this); | |
188 $('save-button').onclick = onSave.bind(this); | 179 $('save-button').onclick = onSave.bind(this); |
| 180 $('clear-button').onclick = clearDebugInfo.bind(this); |
189 } | 181 } |
190 | 182 |
191 return { | 183 return { |
192 initialize: initialize, | 184 initialize: initialize, |
193 getDebugInfoResult: getDebugInfoResult, | 185 getDebugInfoResult: getDebugInfoResult, |
194 getPreferenceValueResult: getPreferenceValueResult | 186 getPreferenceValueResult: getPreferenceValueResult |
195 }; | 187 }; |
196 })(); | 188 })(); |
197 | 189 |
198 document.addEventListener('DOMContentLoaded', instantConfig.initialize); | 190 document.addEventListener('DOMContentLoaded', instantConfig.initialize); |
OLD | NEW |