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 // eslint-disable-next-line no-restricted-properties | 8 // eslint-disable-next-line no-restricted-properties |
9 var $ = function(id) { return document.getElementById(id); }; | 9 var $ = function(id) { |
| 10 return document.getElementById(id); |
| 11 }; |
10 | 12 |
11 /** | 13 /** |
12 * WebUI for configuring instant.* preference values used by | 14 * WebUI for configuring instant.* preference values used by |
13 * Chrome's instant search system. | 15 * Chrome's instant search system. |
14 */ | 16 */ |
15 var instantConfig = (function() { | 17 var instantConfig = (function() { |
16 'use strict'; | 18 'use strict'; |
17 | 19 |
18 /** List of fields used to dynamically build form. **/ | 20 /** List of fields used to dynamically build form. **/ |
19 var FIELDS = [ | 21 var FIELDS = [ |
(...skipping 30 matching lines...) Expand all Loading... |
50 row.id = ''; | 52 row.id = ''; |
51 | 53 |
52 var label = createElementWithClass('label', 'row-label'); | 54 var label = createElementWithClass('label', 'row-label'); |
53 label.setAttribute('for', field.key); | 55 label.setAttribute('for', field.key); |
54 label.textContent = field.label; | 56 label.textContent = field.label; |
55 row.appendChild(label); | 57 row.appendChild(label); |
56 | 58 |
57 var input = createElementWithClass('input', 'row-input'); | 59 var input = createElementWithClass('input', 'row-input'); |
58 input.type = field.type; | 60 input.type = field.type; |
59 input.id = field.key; | 61 input.id = field.key; |
60 input.title = "Default Value: " + field.default; | 62 input.title = 'Default Value: ' + field.default; |
61 if (field.size) input.size = field.size; | 63 if (field.size) |
| 64 input.size = field.size; |
62 input.min = field.min || 0; | 65 input.min = field.min || 0; |
63 if (field.max) input.max = field.max; | 66 if (field.max) |
64 if (field.step) input.step = field.step; | 67 input.max = field.max; |
| 68 if (field.step) |
| 69 input.step = field.step; |
65 row.appendChild(input); | 70 row.appendChild(input); |
66 | 71 |
67 var units = createElementWithClass('div', 'row-units'); | 72 var units = createElementWithClass('div', 'row-units'); |
68 if (field.units) units.innerHTML = field.units; | 73 if (field.units) |
| 74 units.innerHTML = field.units; |
69 row.appendChild(units); | 75 row.appendChild(units); |
70 | 76 |
71 $('instant-form').appendChild(row); | 77 $('instant-form').appendChild(row); |
72 } | 78 } |
73 } | 79 } |
74 | 80 |
75 /** | 81 /** |
76 * Initialize the form by adding 'onChange' listeners to all fields. | 82 * Initialize the form by adding 'onChange' listeners to all fields. |
77 */ | 83 */ |
78 function initForm() { | 84 function initForm() { |
79 for (var i = 0; i < FIELDS.length; i++) { | 85 for (var i = 0; i < FIELDS.length; i++) { |
80 var field = FIELDS[i]; | 86 var field = FIELDS[i]; |
81 $(field.key).onchange = (function(key) { | 87 $(field.key).onchange = (function(key) { |
82 setPreferenceValue(key); | 88 setPreferenceValue(key); |
83 }).bind(null, field.key); | 89 }).bind(null, field.key); |
84 } | 90 } |
85 } | 91 } |
86 | 92 |
87 /** | 93 /** |
88 * Request a preference setting's value. | 94 * Request a preference setting's value. |
89 * This method is asynchronous; the result is provided by a call to | 95 * This method is asynchronous; the result is provided by a call to |
90 * getPreferenceValueResult. | 96 * getPreferenceValueResult. |
91 * @param {string} prefName The name of the preference value being requested. | 97 * @param {string} prefName The name of the preference value being requested. |
92 */ | 98 */ |
93 function getPreferenceValue(prefName) { | 99 function getPreferenceValue(prefName) { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 } | 188 } |
183 | 189 |
184 return { | 190 return { |
185 initialize: initialize, | 191 initialize: initialize, |
186 getDebugInfoResult: getDebugInfoResult, | 192 getDebugInfoResult: getDebugInfoResult, |
187 getPreferenceValueResult: getPreferenceValueResult | 193 getPreferenceValueResult: getPreferenceValueResult |
188 }; | 194 }; |
189 })(); | 195 })(); |
190 | 196 |
191 document.addEventListener('DOMContentLoaded', instantConfig.initialize); | 197 document.addEventListener('DOMContentLoaded', instantConfig.initialize); |
OLD | NEW |