Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 (function() { | 5 (function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 cr.define('cr.translateInternals', function() { | 8 cr.define('cr.translateInternals', function() { |
| 9 | 9 |
| 10 var detectionLogs_ = null; | 10 var detectionLogs_ = null; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 chrome.send('requestInfo'); | 24 chrome.send('requestInfo'); |
| 25 | 25 |
| 26 var button = $('detection-logs-dump'); | 26 var button = $('detection-logs-dump'); |
| 27 button.addEventListener('click', onDetectionLogsDump); | 27 button.addEventListener('click', onDetectionLogsDump); |
| 28 | 28 |
| 29 var enableTranslateSettings = templateData['enable-translate-settings']; | 29 var enableTranslateSettings = templateData['enable-translate-settings']; |
| 30 if (!enableTranslateSettings) { | 30 if (!enableTranslateSettings) { |
| 31 $('prefs-blocked-languages').hidden = true; | 31 $('prefs-blocked-languages').hidden = true; |
| 32 $('prefs-language-blacklist').querySelector('h2 span').hidden = true; | 32 $('prefs-language-blacklist').querySelector('h2 span').hidden = true; |
| 33 } | 33 } |
| 34 | |
| 35 var tabpanelNodeList = document.getElementsByTagName('tabpanel'); | |
| 36 var tabpanels = Array.prototype.slice.call(tabpanelNodeList, 0); | |
| 37 var tabpanelIds = tabpanels.map(function(tab) { | |
| 38 return tab.id; | |
| 39 }); | |
| 40 | |
| 41 var tabNodeList = document.getElementsByTagName('tab'); | |
| 42 var tabs = Array.prototype.slice.call(tabNodeList, 0); | |
| 43 tabs.forEach(function(tab) { | |
| 44 tab.onclick = function(e) { | |
| 45 var tabbox = document.querySelector('tabbox'); | |
| 46 var tabpanel = tabpanels[tabbox.selectedIndex]; | |
| 47 var hash = tabpanel.id.match(/(?:^tabpanel-)(.+)/)[1]; | |
| 48 window.location.hash = hash; | |
| 49 }; | |
| 50 }); | |
| 51 | |
| 52 window.onhashchange = function(e) { | |
| 53 var hash = window.location.hash; | |
| 54 | |
| 55 // Remove the first character '#'. | |
| 56 hash = hash.substring(1); | |
| 57 | |
| 58 var id = 'tabpanel-' + hash; | |
| 59 if (tabpanelIds.indexOf(id) == -1) | |
| 60 return; | |
| 61 | |
| 62 $(id).selected = true; | |
| 63 }; | |
| 34 } | 64 } |
| 35 | 65 |
| 36 /** | 66 /** |
| 37 * Creates a new LI element with a button to dismiss the item. | 67 * Creates a new LI element with a button to dismiss the item. |
| 38 * | 68 * |
| 39 * @param {string} text The lable of the LI element. | 69 * @param {string} text The lable of the LI element. |
| 40 * @param {Function} func Callback called when the button is clicked. | 70 * @param {Function} func Callback called when the button is clicked. |
| 41 */ | 71 */ |
| 42 function createLIWithDismissingButton(text, func) { | 72 function createLIWithDismissingButton(text, func) { |
| 43 var span = document.createElement('span'); | 73 var span = document.createElement('span'); |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 'detection-logs-content'); | 322 'detection-logs-content'); |
| 293 | 323 |
| 294 // TD (and TR) can't use the CSS property 'max-height', so DIV | 324 // TD (and TR) can't use the CSS property 'max-height', so DIV |
| 295 // in the content is needed. | 325 // in the content is needed. |
| 296 var contentTD = tr.querySelector('.detection-logs-content'); | 326 var contentTD = tr.querySelector('.detection-logs-content'); |
| 297 var div = document.createElement('div'); | 327 var div = document.createElement('div'); |
| 298 div.textContent = contentTD.textContent; | 328 div.textContent = contentTD.textContent; |
| 299 contentTD.textContent = ''; | 329 contentTD.textContent = ''; |
| 300 contentTD.appendChild(div); | 330 contentTD.appendChild(div); |
| 301 | 331 |
| 302 var tbody = $('detection-logs').getElementsByTagName('tbody')[0]; | 332 var tabpanel = $('tabpanel-detection-logs'); |
|
Evan Stade
2013/07/22 19:06:04
no need to stick this in its own var
| |
| 333 var tbody = tabpanel.getElementsByTagName('tbody')[0]; | |
| 303 tbody.appendChild(tr); | 334 tbody.appendChild(tr); |
| 304 } | 335 } |
| 305 | 336 |
| 306 /** | 337 /** |
| 307 * Handles the message of 'translateErrorDetailsAdded' from the | 338 * Handles the message of 'translateErrorDetailsAdded' from the |
| 308 * browser. | 339 * browser. |
| 309 * | 340 * |
| 310 * @param {Object} details The object which represents the logs. | 341 * @param {Object} details The object which represents the logs. |
| 311 */ | 342 */ |
| 312 function onTranslateErrorDetailsAdded(details) { | 343 function onTranslateErrorDetailsAdded(details) { |
| 313 var tr = document.createElement('tr'); | 344 var tr = document.createElement('tr'); |
| 314 | 345 |
| 315 appendTD(tr, formatDate(new Date(details['time'])), 'error-logs-time'); | 346 appendTD(tr, formatDate(new Date(details['time'])), 'error-logs-time'); |
| 316 appendTD(tr, details['url'], 'error-logs-url'); | 347 appendTD(tr, details['url'], 'error-logs-url'); |
| 317 appendTD( | 348 appendTD( |
| 318 tr, | 349 tr, |
| 319 details['error'] + ': ' + formatTranslateErrorsType(details['error']), | 350 details['error'] + ': ' + formatTranslateErrorsType(details['error']), |
| 320 'error-logs-error'); | 351 'error-logs-error'); |
| 321 | 352 |
| 322 var tbody = $('error-logs').getElementsByTagName('tbody')[0]; | 353 var tabpanel = $('tabpanel-error-logs'); |
|
Evan Stade
2013/07/22 19:06:04
no need to stick this in its own var
| |
| 354 var tbody = tabpanel.getElementsByTagName('tbody')[0]; | |
| 323 tbody.appendChild(tr); | 355 tbody.appendChild(tr); |
| 324 } | 356 } |
| 325 | 357 |
| 326 /** | 358 /** |
| 327 * Handles the message of 'translateEventDetailsAdded' from the browser. | 359 * Handles the message of 'translateEventDetailsAdded' from the browser. |
| 328 * | 360 * |
| 329 * @param {Object} details The object which contains event information. | 361 * @param {Object} details The object which contains event information. |
| 330 */ | 362 */ |
| 331 function onTranslateEventDetailsAdded(details) { | 363 function onTranslateEventDetailsAdded(details) { |
| 332 var tr = document.createElement('tr'); | 364 var tr = document.createElement('tr'); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 /** | 430 /** |
| 399 * The entry point of the UI. | 431 * The entry point of the UI. |
| 400 */ | 432 */ |
| 401 function main() { | 433 function main() { |
| 402 cr.doc.addEventListener('DOMContentLoaded', | 434 cr.doc.addEventListener('DOMContentLoaded', |
| 403 cr.translateInternals.initialize); | 435 cr.translateInternals.initialize); |
| 404 } | 436 } |
| 405 | 437 |
| 406 main(); | 438 main(); |
| 407 })(); | 439 })(); |
| OLD | NEW |