OLD | NEW |
1 // Copyright (c) 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 /** |
11 * WebUI for configuring instant.* preference values used by | 11 * WebUI for configuring instant.* preference values used by |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 input.type = field.type; | 57 input.type = field.type; |
58 input.id = field.key; | 58 input.id = field.key; |
59 input.title = "Default Value: " + field.default; | 59 input.title = "Default Value: " + field.default; |
60 if (field.size) input.size = field.size; | 60 if (field.size) input.size = field.size; |
61 input.min = field.min || 0; | 61 input.min = field.min || 0; |
62 if (field.max) input.max = field.max; | 62 if (field.max) input.max = field.max; |
63 if (field.step) input.step = field.step; | 63 if (field.step) input.step = field.step; |
64 row.appendChild(input); | 64 row.appendChild(input); |
65 | 65 |
66 var units = createElementWithClass('div', 'row-units'); | 66 var units = createElementWithClass('div', 'row-units'); |
67 if (field.units) | 67 if (field.units) units.innerHTML = field.units; |
68 units.innerHTML = field.units; | |
69 row.appendChild(units); | 68 row.appendChild(units); |
70 | 69 |
71 $('instant-form').appendChild(row); | 70 $('instant-form').appendChild(row); |
72 } | 71 } |
73 } | 72 } |
74 | 73 |
75 /** | 74 /** |
76 * Initialize the form by adding 'onChange' listeners to all fields. | 75 * Initialize the form by adding 'onChange' listeners to all fields. |
77 */ | 76 */ |
78 function initForm() { | 77 function initForm() { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 * @param {string} prefName The name of the preference value being set. | 110 * @param {string} prefName The name of the preference value being set. |
112 */ | 111 */ |
113 function setPreferenceValue(prefName) { | 112 function setPreferenceValue(prefName) { |
114 var value; | 113 var value; |
115 if ($(prefName).type == 'checkbox') | 114 if ($(prefName).type == 'checkbox') |
116 value = $(prefName).checked; | 115 value = $(prefName).checked; |
117 else if ($(prefName).type == 'number') | 116 else if ($(prefName).type == 'number') |
118 value = parseFloat($(prefName).value); | 117 value = parseFloat($(prefName).value); |
119 else | 118 else |
120 value = $(prefName).value; | 119 value = $(prefName).value; |
121 chrome.send( | 120 chrome.send('setPreferenceValue', [prefName, value]); |
122 'setPreferenceValue', | |
123 [prefName, value]); | |
124 } | 121 } |
125 | 122 |
126 /** | 123 /** |
127 * Handle processing of "Reset" button. | 124 * Handle processing of "Reset" button. |
128 * Causes off form values to be updated based on current preference values. | 125 * Causes off form values to be updated based on current preference values. |
129 */ | 126 */ |
130 function onReset() { | 127 function onReset() { |
131 for (var i = 0; i < FIELDS.length; i++) { | 128 for (var i = 0; i < FIELDS.length; i++) { |
132 var field = FIELDS[i]; | 129 var field = FIELDS[i]; |
133 if ($(field.key).type == 'checkbox') | 130 if ($(field.key).type == 'checkbox') |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 } | 189 } |
193 | 190 |
194 return { | 191 return { |
195 initialize: initialize, | 192 initialize: initialize, |
196 getDebugInfoResult: getDebugInfoResult, | 193 getDebugInfoResult: getDebugInfoResult, |
197 getPreferenceValueResult: getPreferenceValueResult | 194 getPreferenceValueResult: getPreferenceValueResult |
198 }; | 195 }; |
199 })(); | 196 })(); |
200 | 197 |
201 document.addEventListener('DOMContentLoaded', instantConfig.initialize); | 198 document.addEventListener('DOMContentLoaded', instantConfig.initialize); |
OLD | NEW |