Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1057)

Side by Side Diff: chrome/browser/resources/instant/instant.js

Issue 10933023: Control zero suggest with a pref, not a switch. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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
12 * Chrome's instant search system. 12 * Chrome's instant search system.
13 */ 13 */
14 var instantConfig = (function() { 14 var instantConfig = (function() {
15 'use strict'; 15 'use strict';
16 16
17 /** List of fields used to dynamically build form. **/ 17 /** List of fields used to dynamically build form. **/
18 var FIELDS = [ 18 var FIELDS = [
19 { 19 {
20 key: 'instant.animation_scale_factor', 20 key: 'instant.animation_scale_factor',
21 label: 'Slow down animations by a factor of', 21 label: 'Slow down animations by a factor of',
22 type: 'float',
22 units: 'no units, range 1 to 10', 23 units: 'no units, range 1 to 10',
23 default: 1 24 default: 1
25 },
26 {
27 key: 'instant.experimental_zero_suggest_url_prefix',
28 label: 'Prefix URL for the (experimental) ZeroSuggest provider',
29 type: 'string',
30 units: '',
31 default: ''
24 } 32 }
25 ]; 33 ];
26 34
27 /** 35 /**
28 * Returns a DOM element of the given type and class name. 36 * Returns a DOM element of the given type and class name.
29 */ 37 */
30 function createElementWithClass(elementType, className) { 38 function createElementWithClass(elementType, className) {
31 var element = document.createElement(elementType); 39 var element = document.createElement(elementType);
32 element.className = className; 40 element.className = className;
33 return element; 41 return element;
(...skipping 11 matching lines...) Expand all
45 53
46 var row = createElementWithClass('div', 'row'); 54 var row = createElementWithClass('div', 'row');
47 row.id = ''; 55 row.id = '';
48 56
49 var label = createElementWithClass('label', 'row-label'); 57 var label = createElementWithClass('label', 'row-label');
50 label.setAttribute('for', field.key); 58 label.setAttribute('for', field.key);
51 label.textContent = field.label; 59 label.textContent = field.label;
52 row.appendChild(label); 60 row.appendChild(label);
53 61
54 var input = createElementWithClass('input', 'row-input'); 62 var input = createElementWithClass('input', 'row-input');
55 input.type = 'number';
56 input.size = 3;
57 input.id = field.key; 63 input.id = field.key;
58 input.min = field.min || 0;
59 input.title = "Default Value: " + field.default; 64 input.title = "Default Value: " + field.default;
60 if (field.max) input.max = field.max; 65 if (field.type == 'float') {
61 if (field.step) input.step = field.step; 66 input.size = 3;
67 input.type = 'number';
68 input.min = field.min || 0;
69 if (field.max) input.max = field.max;
70 if (field.step) input.step = field.step;
71 } else {
72 input.size = 40;
73 }
62 row.appendChild(input); 74 row.appendChild(input);
63 75
64 var units = createElementWithClass('div', 'row-units'); 76 var units = createElementWithClass('div', 'row-units');
65 if (field.units) 77 if (field.units)
66 units.innerHTML = field.units; 78 units.innerHTML = field.units;
67 row.appendChild(units); 79 row.appendChild(units);
68 80
69 $('instant-form').appendChild(row); 81 $('instant-form').appendChild(row);
70 } 82 }
71 } 83 }
(...skipping 28 matching lines...) Expand all
100 function getPreferenceValueResult(prefName, value) { 112 function getPreferenceValueResult(prefName, value) {
101 $(prefName).value = value; 113 $(prefName).value = value;
102 } 114 }
103 115
104 /** 116 /**
105 * Set a preference setting's value. 117 * Set a preference setting's value.
106 * @param {string} prefName The name of the preference value being set. 118 * @param {string} prefName The name of the preference value being set.
107 * @param {value} value The value to be associated with prefName. 119 * @param {value} value The value to be associated with prefName.
108 */ 120 */
109 function setPreferenceValue(prefName, value) { 121 function setPreferenceValue(prefName, value) {
110 chrome.send( 122 chrome.send('setPreferenceValue', [prefName, value]);
111 'setPreferenceValue',
112 [prefName, parseFloat(value)]);
113 } 123 }
114 124
115 /** 125 /**
116 * Handle processing of "Reset" button. 126 * Handle processing of "Reset" button.
117 * Causes off form values to be updated based on current preference values. 127 * Causes off form values to be updated based on current preference values.
118 */ 128 */
119 function onReset() { 129 function onReset() {
120 for (var i = 0; i < FIELDS.length; i++) { 130 for (var i = 0; i < FIELDS.length; i++) {
121 var field = FIELDS[i]; 131 var field = FIELDS[i];
122 $(field.key).value = field.default; 132 $(field.key).value = field.default;
123 setPreferenceValue(field.key, field.default); 133 setPreferenceValue(field.key, field.default);
124 } 134 }
125 return false; 135 return false;
126 } 136 }
127 137
128 /** 138 /**
129 * Saves data back into Chrome preferences. 139 * Saves data back into Chrome preferences.
130 */ 140 */
131 function onSave() { 141 function onSave() {
132 for (var i = 0; i < FIELDS.length; i++) { 142 for (var i = 0; i < FIELDS.length; i++) {
133 var field = FIELDS[i]; 143 var field = FIELDS[i];
134 setPreferenceValue(field.key, $(field.key).value); 144 var value = $(field.key).value;
145 setPreferenceValue(
146 field.key, (field.type == 'float') ? parseFloat(value) : value);
135 } 147 }
136 return false; 148 return false;
137 } 149 }
138 150
139 151
140 function loadForm() { 152 function loadForm() {
141 for (var i = 0; i < FIELDS.length; i++) 153 for (var i = 0; i < FIELDS.length; i++)
142 getPreferenceValue(FIELDS[i].key); 154 getPreferenceValue(FIELDS[i].key);
143 } 155 }
144 156
145 /** 157 /**
146 * Build and initialize the configuration form. 158 * Build and initialize the configuration form.
147 */ 159 */
148 function initialize() { 160 function initialize() {
149 buildForm(); 161 buildForm();
150 loadForm(); 162 loadForm();
151 initForm(); 163 initForm();
152 164
153 $('reset-button').onclick = onReset.bind(this); 165 $('reset-button').onclick = onReset.bind(this);
154 $('save-button').onclick = onSave.bind(this); 166 $('save-button').onclick = onSave.bind(this);
155 } 167 }
156 168
157 return { 169 return {
158 initialize: initialize, 170 initialize: initialize,
159 getPreferenceValueResult: getPreferenceValueResult 171 getPreferenceValueResult: getPreferenceValueResult
160 }; 172 };
161 })(); 173 })();
162 174
163 document.addEventListener('DOMContentLoaded', instantConfig.initialize); 175 document.addEventListener('DOMContentLoaded', instantConfig.initialize);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698