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

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

Issue 10010019: JS style nits (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 /** 5 /**
6 * This variable structure is here to document the structure that the template 6 * This variable structure is here to document the structure that the template
7 * expects to correctly populate the page. 7 * expects to correctly populate the page.
8 */ 8 */
9 var flagsExperimentsDataFormat = { 9 var flagsExperimentsDataFormat = {
10 'flagsExperiments': [ 10 'flagsExperiments': [
Dan Beam 2012/04/05 22:24:13 I think we generally don't put '' around the key n
11 { 11 {
12 'internal_name': 'Experiment ID string', 12 'internal_name': 'Experiment ID string',
13 'name': 'Experiment Name', 13 'name': 'Experiment Name',
14 'description': 'description', 14 'description': 'description',
15 // enabled is only set if the experiment is single valued. 15 // enabled is only set if the experiment is single valued.
16 'enabled': true, 16 'enabled': true,
17 // choices is only set if the experiment has multiple values. 17 // choices is only set if the experiment has multiple values.
18 'choices': [ 18 'choices': [
19 { 19 {
20 'internal_name': 'Experiment ID string', 20 'internal_name': 'Experiment ID string',
(...skipping 19 matching lines...) Expand all
40 */ 40 */
41 function renderTemplate(flagsExperimentsData) { 41 function renderTemplate(flagsExperimentsData) {
42 // This is the javascript code that processes the template: 42 // This is the javascript code that processes the template:
43 var input = new JsEvalContext(flagsExperimentsData); 43 var input = new JsEvalContext(flagsExperimentsData);
44 var output = document.getElementById('flagsExperimentTemplate'); 44 var output = document.getElementById('flagsExperimentTemplate');
45 jstProcess(input, output); 45 jstProcess(input, output);
46 46
47 // Add handlers to dynamically created HTML elements. 47 // Add handlers to dynamically created HTML elements.
48 var elements = document.getElementsByClassName('experiment-select'); 48 var elements = document.getElementsByClassName('experiment-select');
49 for (var i = 0; i < elements.length; ++i) { 49 for (var i = 0; i < elements.length; ++i) {
50 elements[i].onchange = function () { 50 elements[i].onchange = function() {
Dan Beam 2012/04/05 22:24:13 STEPHEN! (jk, saw this when I reviewed his patch,
51 handleSelectChoiceExperiment(this, this.selectedIndex); 51 handleSelectChoiceExperiment(this, this.selectedIndex);
52 return false; 52 return false;
53 }; 53 };
54 } 54 }
55 55
56 elements = document.getElementsByClassName('experiment-disable-link'); 56 elements = document.getElementsByClassName('experiment-disable-link');
57 for (var i = 0; i < elements.length; ++i) { 57 for (var i = 0; i < elements.length; ++i) {
58 elements[i].onclick = function () { 58 elements[i].onclick = function() {
59 handleEnableExperiment(this, false); 59 handleEnableExperiment(this, false);
60 return false; 60 return false;
61 }; 61 };
62 } 62 }
63 63
64 elements = document.getElementsByClassName('experiment-enable-link'); 64 elements = document.getElementsByClassName('experiment-enable-link');
65 for (var i = 0; i < elements.length; ++i) { 65 for (var i = 0; i < elements.length; ++i) {
66 elements[i].onclick = function () { 66 elements[i].onclick = function() {
67 handleEnableExperiment(this, true); 67 handleEnableExperiment(this, true);
68 return false; 68 return false;
69 }; 69 };
70 } 70 }
71 71
72 elements = document.getElementsByClassName('experiment-restart-button'); 72 elements = document.getElementsByClassName('experiment-restart-button');
73 for (var i = 0; i < elements.length; ++i) { 73 for (var i = 0; i < elements.length; ++i) {
74 elements[i].onclick = restartBrowser; 74 elements[i].onclick = restartBrowser;
75 } 75 }
76 } 76 }
77 77
78 /** 78 /**
79 * Asks the C++ FlagsDOMHandler to get details about the available experiments 79 * Asks the C++ FlagsDOMHandler to get details about the available experiments
80 * and return detailed data about the configuration. The FlagsDOMHandler 80 * and return detailed data about the configuration. The FlagsDOMHandler
81 * should reply to returnFlagsExperiments() (below). 81 * should reply to returnFlagsExperiments() (below).
82 */ 82 */
83 function requestFlagsExperimentsData() { 83 function requestFlagsExperimentsData() {
84 chrome.send('requestFlagsExperiments', []); 84 chrome.send('requestFlagsExperiments');
85 } 85 }
86 86
87 /** 87 /**
88 * Asks the C++ FlagsDOMHandler to restart the browser (restoring tabs). 88 * Asks the C++ FlagsDOMHandler to restart the browser (restoring tabs).
89 */ 89 */
90 function restartBrowser() { 90 function restartBrowser() {
91 chrome.send('restartBrowser', []); 91 chrome.send('restartBrowser');
92 } 92 }
93 93
94 /** 94 /**
95 * Called by the WebUI to re-populate the page with data representing the 95 * Called by the WebUI to re-populate the page with data representing the
96 * current state of installed experiments. 96 * current state of installed experiments.
97 */ 97 */
98 function returnFlagsExperiments(flagsExperimentsData){ 98 function returnFlagsExperiments(flagsExperimentsData) {
99 var bodyContainer = document.getElementById('body-container'); 99 var bodyContainer = document.getElementById('body-container');
100 renderTemplate(flagsExperimentsData); 100 renderTemplate(flagsExperimentsData);
101 bodyContainer.style.visibility = 'visible'; 101 bodyContainer.style.visibility = 'visible';
102 } 102 }
103 103
104 /** 104 /**
105 * Handles a 'enable' or 'disable' button getting clicked. 105 * Handles a 'enable' or 'disable' button getting clicked.
106 */ 106 */
107 function handleEnableExperiment(node, enable) { 107 function handleEnableExperiment(node, enable) {
108 // Tell the C++ FlagsDOMHandler to enable/disable the experiment. 108 // Tell the C++ FlagsDOMHandler to enable/disable the experiment.
109 chrome.send('enableFlagsExperiment', [String(node.internal_name), 109 chrome.send('enableFlagsExperiment', [String(node.internal_name),
110 String(enable)]); 110 String(enable)]);
Dan Beam 2012/04/05 22:24:13 +1\s
Tyler Breisacher (Chromium) 2012/04/05 22:49:55 Done.
111 requestFlagsExperimentsData(); 111 requestFlagsExperimentsData();
112 } 112 }
113 113
114 /** 114 /**
115 * Invoked when the selection of a multi-value choice is changed to the 115 * Invoked when the selection of a multi-value choice is changed to the
116 * specified index. 116 * specified index.
117 */ 117 */
118 function handleSelectChoiceExperiment(node, index) { 118 function handleSelectChoiceExperiment(node, index) {
119 // Tell the C++ FlagsDOMHandler to enable the selected choice. 119 // Tell the C++ FlagsDOMHandler to enable the selected choice.
120 chrome.send('enableFlagsExperiment', 120 chrome.send('enableFlagsExperiment',
121 [String(node.internal_name) + "@" + index, "true"]); 121 [String(node.internal_name) + '@' + index, 'true']);
Dan Beam 2012/04/05 22:24:13 'true' vs. true?!
Tyler Breisacher (Chromium) 2012/04/05 22:49:55 The C++ is probably set up to only take strings. I
122 requestFlagsExperimentsData(); 122 requestFlagsExperimentsData();
123 } 123 }
124 124
125 // Get data and have it displayed upon loading. 125 // Get data and have it displayed upon loading.
126 document.addEventListener('DOMContentLoaded', requestFlagsExperimentsData); 126 document.addEventListener('DOMContentLoaded', requestFlagsExperimentsData);
127 127
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698