base/threading: remove ScopedTracker placed for experiments
[chromium-blink-merge.git] / ui / accessibility / extensions / highcontrast / popup.js
blobbdf95ccd863b8d018de6769bb85e09beb2a84df7
1 // Copyright (c) 2014 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.
5 var site;
6 var key1;
7 var key2;
9 function setRadio(name, value) {
10 var radios = document.querySelectorAll('input[name="' + name + '"]');
11 for (var i = 0; i < radios.length; i++) {
12 radios[i].checked = (radios[i].value == value);
13 radios[i].disabled = !getEnabled();
17 function update() {
18 document.body.className = getEnabled() ? '' : 'disabled';
20 if (getEnabled()) {
21 $('title').innerText = chrome.i18n.getMessage('highcontrast_enabled');
22 $('toggle').innerHTML =
23 '<b>' + chrome.i18n.getMessage('highcontrast_disable') + '</b><br>' +
24 '<span class="kb">(' + key1 + ')</span>';
25 $('subcontrols').style.display = 'block';
26 } else {
27 $('title').innerText = chrome.i18n.getMessage('highcontrast_disabled');
28 $('toggle').innerHTML =
29 '<b>' + chrome.i18n.getMessage('highcontrast_enable') + '</b><br>' +
30 '<span class="kb">(' + key1 + ')</span>';
31 $('subcontrols').style.display = 'none';
34 setRadio('keyaction', getKeyAction());
35 if (site) {
36 setRadio('scheme', getSiteScheme(site));
37 $('make_default').disabled = (getSiteScheme(site) == getDefaultScheme());
38 } else {
39 setRadio('scheme', getDefaultScheme());
41 if (getEnabled()) {
42 document.documentElement.setAttribute(
43 'hc',
44 site ? 'a' + getSiteScheme(site) : 'a' + getDefaultScheme());
45 } else {
46 document.documentElement.setAttribute('hc', 'a0');
48 chrome.extension.getBackgroundPage().updateTabs();
51 function onToggle() {
52 setEnabled(!getEnabled());
53 update();
56 function onForget() {
57 resetSiteSchemes();
58 update();
61 function onRadioChange(name, value) {
62 switch (name) {
63 case 'keyaction':
64 setKeyAction(value);
65 break;
66 case 'apply':
67 setApply(value);
68 break;
69 case 'scheme':
70 if (site) {
71 setSiteScheme(site, value);
72 } else {
73 setDefaultScheme(value);
75 break;
77 update();
80 function onMakeDefault() {
81 setDefaultScheme(getSiteScheme(site));
82 update();
85 function addRadioListeners(name) {
86 var radios = document.querySelectorAll('input[name="' + name + '"]');
87 for (var i = 0; i < radios.length; i++) {
88 radios[i].addEventListener('change', function(evt) {
89 onRadioChange(evt.target.name, evt.target.value);
90 }, false);
91 radios[i].addEventListener('click', function(evt) {
92 onRadioChange(evt.target.name, evt.target.value);
93 }, false);
97 function init() {
98 var i18nElements = document.querySelectorAll('*[i18n-content]');
99 for (var i = 0; i < i18nElements.length; i++) {
100 var elem = i18nElements[i];
101 var msg = elem.getAttribute('i18n-content');
102 elem.innerHTML = chrome.i18n.getMessage(msg);
105 addRadioListeners('keyaction');
106 addRadioListeners('apply');
107 addRadioListeners('scheme');
108 $('toggle').addEventListener('click', onToggle, false);
109 $('make_default').addEventListener('click', onMakeDefault, false);
110 $('forget').addEventListener('click', onForget, false);
111 if (navigator.appVersion.indexOf('Mac') != -1) {
112 key1 = '&#x2318;+Shift+F11';
113 key2 = '&#x2318;+Shift+F12';
114 } else {
115 key1 = 'Shift+F11';
116 key2 = 'Shift+F12';
119 chrome.windows.getLastFocused({'populate': true}, function(window) {
120 for (var i = 0; i < window.tabs.length; i++) {
121 var tab = window.tabs[i];
122 if (tab.active) {
123 if (isDisallowedUrl(tab.url)) {
124 $('scheme_title').innerText =
125 chrome.i18n.getMessage('highcontrast_default');
126 $('make_default').style.display = 'none';
127 } else {
128 site = siteFromUrl(tab.url);
129 $('scheme_title').innerHTML =
130 chrome.i18n.getMessage('highcontrast_',
131 '<b>' + site + '</b>:<br>' +
132 '<span class="kb">(' + key2 + ')</span>');
133 $('make_default').style.display = 'block';
135 update();
136 return;
139 site = 'unknown site';
140 update();
144 window.addEventListener('load', init, false);