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

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

Issue 588363002: WebUI: Update some more uses of the old-style i18ntemplate/LocalStrings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: IDS_CANCEL change is in a different cl Created 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 var localStrings;
6
7 // Contents of lines that act as delimiters for multi-line values. 5 // Contents of lines that act as delimiters for multi-line values.
8 var DELIM_START = '---------- START ----------'; 6 var DELIM_START = '---------- START ----------';
9 var DELIM_END = '---------- END ----------'; 7 var DELIM_END = '---------- END ----------';
10 8
11 // Limit file size to 10 MiB to prevent hanging on accidental upload. 9 // Limit file size to 10 MiB to prevent hanging on accidental upload.
12 var MAX_FILE_SIZE = 10485760; 10 var MAX_FILE_SIZE = 10485760;
13 11
14 function getValueDivForButton(button) { 12 function getValueDivForButton(button) {
15 return $(button.id.substr(0, button.id.length - 4)); 13 return $(button.id.substr(0, button.id.length - 4));
16 } 14 }
17 15
18 function getButtonForValueDiv(valueDiv) { 16 function getButtonForValueDiv(valueDiv) {
19 return $(valueDiv.id + '-btn'); 17 return $(valueDiv.id + '-btn');
20 } 18 }
21 19
22 function handleDragOver(e) { 20 function handleDragOver(e) {
23 e.dataTransfer.dropEffect = 'copy'; 21 e.dataTransfer.dropEffect = 'copy';
24 e.preventDefault(); 22 e.preventDefault();
25 } 23 }
26 24
27 function handleDrop(e) { 25 function handleDrop(e) {
28 var file = e.dataTransfer.files[0]; 26 var file = e.dataTransfer.files[0];
29 if (file) { 27 if (file) {
30 e.preventDefault(); 28 e.preventDefault();
31 importLog(file); 29 importLog(file);
32 } 30 }
33 } 31 }
34 32
35 function showError(fileName) { 33 function showError(fileName) {
36 $('status').textContent = localStrings.getStringF('parseError', fileName); 34 $('status').textContent = loadTimeData.getStringF('parseError', fileName);
37 } 35 }
38 36
39 /** 37 /**
40 * Toggles whether an item is collapsed or expanded. 38 * Toggles whether an item is collapsed or expanded.
41 */ 39 */
42 function changeCollapsedStatus() { 40 function changeCollapsedStatus() {
43 var valueDiv = getValueDivForButton(this); 41 var valueDiv = getValueDivForButton(this);
44 if (valueDiv.parentNode.className == 'number-collapsed') { 42 if (valueDiv.parentNode.className == 'number-collapsed') {
45 valueDiv.parentNode.className = 'number-expanded'; 43 valueDiv.parentNode.className = 'number-expanded';
46 this.textContent = localStrings.getString('collapseBtn'); 44 this.textContent = loadTimeData.getString('collapseBtn');
47 } else { 45 } else {
48 valueDiv.parentNode.className = 'number-collapsed'; 46 valueDiv.parentNode.className = 'number-collapsed';
49 this.textContent = localStrings.getString('expandBtn'); 47 this.textContent = loadTimeData.getString('expandBtn');
50 } 48 }
51 } 49 }
52 50
53 /** 51 /**
54 * Collapses all log items. 52 * Collapses all log items.
55 */ 53 */
56 function collapseAll() { 54 function collapseAll() {
57 var valueDivs = document.getElementsByClassName('stat-value'); 55 var valueDivs = document.getElementsByClassName('stat-value');
58 for (var i = 0; i < valueDivs.length; i++) { 56 for (var i = 0; i < valueDivs.length; i++) {
59 var button = getButtonForValueDiv(valueDivs[i]); 57 var button = getButtonForValueDiv(valueDivs[i]);
60 if (button && button.className != 'button-hidden') { 58 if (button && button.className != 'button-hidden') {
61 button.textContent = localStrings.getString('expandBtn'); 59 button.textContent = loadTimeData.getString('expandBtn');
62 valueDivs[i].parentNode.className = 'number-collapsed'; 60 valueDivs[i].parentNode.className = 'number-collapsed';
63 } 61 }
64 } 62 }
65 } 63 }
66 64
67 /** 65 /**
68 * Expands all log items. 66 * Expands all log items.
69 */ 67 */
70 function expandAll() { 68 function expandAll() {
71 var valueDivs = document.getElementsByClassName('stat-value'); 69 var valueDivs = document.getElementsByClassName('stat-value');
72 for (var i = 0; i < valueDivs.length; i++) { 70 for (var i = 0; i < valueDivs.length; i++) {
73 var button = getButtonForValueDiv(valueDivs[i]); 71 var button = getButtonForValueDiv(valueDivs[i]);
74 if (button && button.className != 'button-hidden') { 72 if (button && button.className != 'button-hidden') {
75 button.textContent = localStrings.getString('collapseBtn'); 73 button.textContent = loadTimeData.getString('collapseBtn');
76 valueDivs[i].parentNode.className = 'number-expanded'; 74 valueDivs[i].parentNode.className = 'number-expanded';
77 } 75 }
78 } 76 }
79 } 77 }
80 78
81 /** 79 /**
82 * Collapse only those log items with multi-line values. 80 * Collapse only those log items with multi-line values.
83 */ 81 */
84 function collapseMultiLineStrings() { 82 function collapseMultiLineStrings() {
85 var valueDivs = document.getElementsByClassName('stat-value'); 83 var valueDivs = document.getElementsByClassName('stat-value');
86 var nameDivs = document.getElementsByClassName('stat-name'); 84 var nameDivs = document.getElementsByClassName('stat-name');
87 for (var i = 0; i < valueDivs.length; i++) { 85 for (var i = 0; i < valueDivs.length; i++) {
88 var button = getButtonForValueDiv(valueDivs[i]); 86 var button = getButtonForValueDiv(valueDivs[i]);
89 button.onclick = changeCollapsedStatus; 87 button.onclick = changeCollapsedStatus;
90 if (valueDivs[i].scrollHeight > (nameDivs[i].scrollHeight * 2)) { 88 if (valueDivs[i].scrollHeight > (nameDivs[i].scrollHeight * 2)) {
91 button.className = ''; 89 button.className = '';
92 button.textContent = localStrings.getString('expandBtn'); 90 button.textContent = loadTimeData.getString('expandBtn');
93 valueDivs[i].parentNode.className = 'number-collapsed'; 91 valueDivs[i].parentNode.className = 'number-collapsed';
94 } else { 92 } else {
95 button.className = 'button-hidden'; 93 button.className = 'button-hidden';
96 valueDivs[i].parentNode.className = 'number'; 94 valueDivs[i].parentNode.className = 'number';
97 } 95 }
98 } 96 }
99 } 97 }
100 98
101 /** 99 /**
102 * Read in a log asynchronously, calling parseSystemLog if successful. 100 * Read in a log asynchronously, calling parseSystemLog if successful.
103 * @param {File} file The file to read. 101 * @param {File} file The file to read.
104 */ 102 */
105 function importLog(file) { 103 function importLog(file) {
106 if (file && file.size <= MAX_FILE_SIZE) { 104 if (file && file.size <= MAX_FILE_SIZE) {
107 var reader = new FileReader(); 105 var reader = new FileReader();
108 reader.onload = function() { 106 reader.onload = function() {
109 if (parseSystemLog(this.result)) { 107 if (parseSystemLog(this.result)) {
110 // Reset table title and status 108 // Reset table title and status
111 $('tableTitle').textContent = 109 $('tableTitle').textContent =
112 localStrings.getStringF('logFileTableTitle', file.name); 110 loadTimeData.getStringF('logFileTableTitle', file.name);
113 $('status').textContent = ''; 111 $('status').textContent = '';
114 } else { 112 } else {
115 showError(file.name); 113 showError(file.name);
116 } 114 }
117 }; 115 };
118 reader.readAsText(file); 116 reader.readAsText(file);
119 } else if (file) { 117 } else if (file) {
120 showError(file.name); 118 showError(file.name);
121 } 119 }
122 } 120 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 while (i < len && lines[i] != DELIM_END) 161 while (i < len && lines[i] != DELIM_END)
164 value += lines[i++] + '\n'; 162 value += lines[i++] + '\n';
165 163
166 // Remove trailing newline. 164 // Remove trailing newline.
167 if (value) 165 if (value)
168 value = value.substr(0, value.length - 1); 166 value = value.substr(0, value.length - 1);
169 } 167 }
170 details.push({'statName': name, 'statValue': value}); 168 details.push({'statName': name, 'statValue': value});
171 } 169 }
172 170
173 templateData['details'] = details; 171 var templateData = {'details': details};
174 i18nTemplate.process(document, templateData); 172 i18nTemplate.process(document, templateData);
175 jstProcess(new JsEvalContext(templateData), $('t')); 173 jstProcess(new JsEvalContext(templateData), $('t'));
176 174
177 collapseMultiLineStrings(); 175 collapseMultiLineStrings();
178 return true; 176 return true;
179 } 177 }
180 178
181 document.addEventListener('DOMContentLoaded', function() { 179 document.addEventListener('DOMContentLoaded', function() {
182 localStrings = new LocalStrings(); 180 jstProcess(loadTimeData.createJsEvalContext(), $('t'));
183 181
184 $('collapseAll').onclick = collapseAll; 182 $('collapseAll').onclick = collapseAll;
185 $('expandAll').onclick = expandAll; 183 $('expandAll').onclick = expandAll;
186 184
187 var tp = $('t'); 185 var tp = $('t');
188 tp.addEventListener('dragover', handleDragOver, false); 186 tp.addEventListener('dragover', handleDragOver, false);
189 tp.addEventListener('drop', handleDrop, false); 187 tp.addEventListener('drop', handleDrop, false);
190 188
191 collapseMultiLineStrings(); 189 collapseMultiLineStrings();
192 }); 190 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/about_sys/about_sys.html ('k') | chrome/browser/resources/chromeos/bluetooth_pair_device.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698