Chromium Code Reviews| 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.innerHTML = chrome.i18n.getMessage(msg); | |
|
kevers
2015/04/27 13:57:36
Thanks for fixing i18n!
Would it be safer to use
dmazzoni
2015/04/27 19:47:47
Done.
| |
| 329 } | |
| 330 | |
| 323 $('setup').onclick = function() { | 331 $('setup').onclick = function() { |
| 332 console.log('Click setup'); | |
|
kevers
2015/04/27 13:57:36
Please remove console.log here and below or switch
dmazzoni
2015/04/27 19:47:47
Done.
| |
| 324 $('setup-panel').classList.remove('collapsed'); | 333 $('setup-panel').classList.remove('collapsed'); |
| 325 // Store current settings in the event of a canceled setup. | 334 // Store current settings in the event of a canceled setup. |
| 326 restoreSettings = { | 335 restoreSettings = { |
| 327 type: getDefaultType(), | 336 type: getDefaultType(), |
| 328 severity: getDefaultSeverity() | 337 severity: getDefaultSeverity() |
| 329 }; | 338 }; |
| 330 // Initalize controls based on current settings. | 339 // Initalize controls based on current settings. |
| 331 setCvdTypeSelection(restoreSettings.type); | 340 setCvdTypeSelection(restoreSettings.type); |
| 332 $('severity').value = restoreSettings.severity; | 341 $('severity').value = restoreSettings.severity; |
| 333 updateControls(); | 342 updateControls(); |
| 334 }; | 343 }; |
| 335 | 344 |
| 345 console.log('init 5'); | |
| 346 | |
| 336 $('delta').addEventListener('input', function() { | 347 $('delta').addEventListener('input', function() { |
| 337 onDeltaChange(parseFloat(this.value)); | 348 onDeltaChange(parseFloat(this.value)); |
| 338 }); | 349 }); |
| 339 $('severity').addEventListener('input', function() { | 350 $('severity').addEventListener('input', function() { |
| 340 onSeverityChange(parseFloat(this.value)); | 351 onSeverityChange(parseFloat(this.value)); |
| 341 }); | 352 }); |
| 342 $('enable').addEventListener('change', function() { | 353 $('enable').addEventListener('change', function() { |
| 343 onEnableChange(this.checked); | 354 onEnableChange(this.checked); |
| 344 }); | 355 }); |
| 345 | 356 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 return; | 402 return; |
| 392 } | 403 } |
| 393 } | 404 } |
| 394 site = 'unknown site'; | 405 site = 'unknown site'; |
| 395 update(); | 406 update(); |
| 396 }); | 407 }); |
| 397 } | 408 } |
| 398 | 409 |
| 399 // TODO(wnwen): Use Promise instead, more reliable. | 410 // TODO(wnwen): Use Promise instead, more reliable. |
| 400 window.addEventListener('load', initialize, false); | 411 window.addEventListener('load', initialize, false); |
| OLD | NEW |