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
3 // found in the LICENSE file.
9 * Update the popup controls based on settings for this site or the default.
13 debugPrint('updated site ' + site + ' to ' +
14 getSiteDelta(site) + ',' + getSiteSeverity(site));
15 $('delta').value = getSiteDelta(site);
16 $('severity').value = getSiteSeverity(site);
18 debugPrint('updated site ' + site + ' to ' +
19 getDefaultDelta() + ',' + getDefaultSeverity());
20 $('delta').value = getDefaultDelta();
21 $('severity').value = getDefaultSeverity();
24 debugPrint('updated site ' + site + ' type ' + getDefaultType());
25 $('type').value = getDefaultType();
27 // TODO(mustaq): Finish simulate feature.
28 //debugPrint('updated site ' + site + ' simulate ' + getDefaultSimulate());
29 //$('simulate').checked = getDefaultSimulate();
31 chrome.extension.getBackgroundPage().updateTabs();
36 * Callback for color rotation slider.
38 * @param {number} value Parsed value of slider element.
40 function onDeltaChange(value) {
41 debugPrint('delta changing to ' + value + ' for site ' + site);
43 setSiteDelta(site, value);
45 setDefaultDelta(value);
51 * Callback for severity slider.
53 * @param {number} value Parsed value of slider element.
55 function onSeverityChange(value) {
56 debugPrint('severity changing to ' + value + ' for site ' + site);
58 setSiteSeverity(site, value);
60 setDefaultSeverity(value);
66 * Callback for changing color deficiency type.
68 * @param {string} value Value of dropdown element.
70 function onTypeChange(value) {
71 debugPrint('type changing to ' + value + ' for site ' + site);
72 setDefaultType(value);
78 * TODO(mustaq): JsDoc.
80 function onSimulateChange(value) {
81 debugPrint('simulate changing to ' + value + ' for site ' + site);
82 setDefaultSimulate(value);
88 * Reset all stored per-site and default values.
91 debugPrint('resetting sites');
93 resetSiteSeverities();
99 * Attach event handlers to controls and update the filter config values for the
100 * currently visible tab.
102 function initialize() {
103 $('delta').addEventListener('input', function() {
104 onDeltaChange(parseFloat(this.value));
106 $('severity').addEventListener('input', function() {
107 onSeverityChange(parseFloat(this.value));
109 $('type').addEventListener('input', function() {
110 onTypeChange(this.value);
112 // TODO(mustaq): Finish simulate feature.
113 //$('simulate').addEventListener('change', function() {
114 // onSimulateChange(!this.checked);
116 $('resetall').addEventListener('click', function() {
120 chrome.windows.getLastFocused({'populate': true}, function(window) {
121 for (var i = 0; i < window.tabs.length; i++) {
122 var tab = window.tabs[i];
124 site = siteFromUrl(tab.url);
125 debugPrint('active tab update ' + site);
130 site = 'unknown site';
135 // TODO(wnwen): Use Promise instead, more reliable.
136 window.addEventListener('load', initialize, false);