| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 site; | 5 var site; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Toggle between filters 0 and 1 in order to force a repaint. | 8 * Toggle between filters 0 and 1 in order to force a repaint. |
| 9 * TODO(kevers): Consolidate with filter in CVD. | 9 * TODO(kevers): Consolidate with filter in CVD. |
| 10 * @type {!number} | 10 * @type {!number} |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 * Creates a radio button for selecting the given type of CVD and a series of | 100 * Creates a radio button for selecting the given type of CVD and a series of |
| 101 * color swatches for testing color vision. | 101 * color swatches for testing color vision. |
| 102 * @param {string} cvdType Type of CVD, either "PROTANOMALY" or "DEUTERANOMALY" | 102 * @param {string} cvdType Type of CVD, either "PROTANOMALY" or "DEUTERANOMALY" |
| 103 * or "TRITANOMALY". | 103 * or "TRITANOMALY". |
| 104 * @return {!Element} Row of color swatches with a leading radio button. | 104 * @return {!Element} Row of color swatches with a leading radio button. |
| 105 */ | 105 */ |
| 106 function createTestRow(type) { | 106 function createTestRow(type) { |
| 107 var toCssColor = function(rgb) { | 107 var toCssColor = function(rgb) { |
| 108 return 'rgb(' + rgb.join(',') + ')'; | 108 return 'rgb(' + rgb.join(',') + ')'; |
| 109 }; | 109 }; |
| 110 var row = document.createElement('div'); | 110 var row = document.createElement('label'); |
| 111 row.classList.add('row'); | 111 row.classList.add('row'); |
| 112 | 112 |
| 113 var button = document.createElement('input'); | 113 var button = document.createElement('input'); |
| 114 button.id = 'select-' + type; | 114 button.id = 'select-' + type; |
| 115 button.name = 'cvdType'; | 115 button.name = 'cvdType'; |
| 116 button.setAttribute('type', 'radio'); | 116 button.setAttribute('type', 'radio'); |
| 117 button.value = type; | 117 button.value = type; |
| 118 button.checked = false; | 118 button.checked = false; |
| 119 row.appendChild(button); | 119 row.appendChild(button); |
| 120 button.addEventListener('change', function() { | 120 button.addEventListener('change', function() { |
| 121 onTypeChange(this.value); | 121 onTypeChange(this.value); |
| 122 }); | 122 }); |
| 123 button.setAttribute('aria-label', type); |
| 123 | 124 |
| 124 SWATCH_COLORS.forEach(function(data) { | 125 SWATCH_COLORS.forEach(function(data) { |
| 125 var swatch = document.querySelector('.swatch.template').cloneNode(true); | 126 var swatch = document.querySelector('.swatch.template').cloneNode(true); |
| 126 swatch.style.background = toCssColor(data.BACKGROUND); | 127 swatch.style.background = toCssColor(data.BACKGROUND); |
| 127 swatch.style.color = toCssColor(data[type]); | 128 swatch.style.color = toCssColor(data[type]); |
| 128 swatch.classList.remove('template'); | 129 swatch.classList.remove('template'); |
| 129 row.appendChild(swatch); | 130 row.appendChild(swatch); |
| 130 }); | 131 }); |
| 131 return row; | 132 return row; |
| 132 } | 133 } |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 debugPrint('onReset'); | 314 debugPrint('onReset'); |
| 314 resetSiteDeltas(); | 315 resetSiteDeltas(); |
| 315 update(); | 316 update(); |
| 316 } | 317 } |
| 317 | 318 |
| 318 /** | 319 /** |
| 319 * Attach event handlers to controls and update the filter config values for the | 320 * Attach event handlers to controls and update the filter config values for the |
| 320 * currently visible tab. | 321 * currently visible tab. |
| 321 */ | 322 */ |
| 322 function initialize() { | 323 function initialize() { |
| 324 var i18nElements = document.querySelectorAll('*[i18n-content]'); |
| 325 for (var i = 0; i < i18nElements.length; i++) { |
| 326 var elem = i18nElements[i]; |
| 327 var msg = elem.getAttribute('i18n-content'); |
| 328 elem.textContent = chrome.i18n.getMessage(msg); |
| 329 } |
| 330 |
| 323 $('setup').onclick = function() { | 331 $('setup').onclick = function() { |
| 324 $('setup-panel').classList.remove('collapsed'); | 332 $('setup-panel').classList.remove('collapsed'); |
| 325 // Store current settings in the event of a canceled setup. | 333 // Store current settings in the event of a canceled setup. |
| 326 restoreSettings = { | 334 restoreSettings = { |
| 327 type: getDefaultType(), | 335 type: getDefaultType(), |
| 328 severity: getDefaultSeverity() | 336 severity: getDefaultSeverity() |
| 329 }; | 337 }; |
| 330 // Initalize controls based on current settings. | 338 // Initalize controls based on current settings. |
| 331 setCvdTypeSelection(restoreSettings.type); | 339 setCvdTypeSelection(restoreSettings.type); |
| 332 $('severity').value = restoreSettings.severity; | 340 $('severity').value = restoreSettings.severity; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 return; | 399 return; |
| 392 } | 400 } |
| 393 } | 401 } |
| 394 site = 'unknown site'; | 402 site = 'unknown site'; |
| 395 update(); | 403 update(); |
| 396 }); | 404 }); |
| 397 } | 405 } |
| 398 | 406 |
| 399 // TODO(wnwen): Use Promise instead, more reliable. | 407 // TODO(wnwen): Use Promise instead, more reliable. |
| 400 window.addEventListener('load', initialize, false); | 408 window.addEventListener('load', initialize, false); |
| OLD | NEW |