OLD | NEW |
1 // Copyright 2016 Google Inc. All rights reserved. | 1 // Copyright 2016 Google Inc. 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 // Disable the whitelist field when it's not relevant. |
| 6 function updateEnabledInputs() { |
| 7 $('whitelist').disabled = !$('disableInApplets').checked; |
| 8 } |
| 9 |
5 // Initialize the page. | 10 // Initialize the page. |
6 function init() { | 11 function init() { |
7 LoadInternationalizedStrings(); | 12 loadInternationalizedStrings(); |
8 | |
9 var blacklist = document.getElementById('blacklist'); | |
10 var checkbox = document.getElementById('disableInApplets'); | |
11 var whitelist = document.getElementById('whitelist'); | |
12 | 13 |
13 // Configure the textboxes, allowing 200 characters for JSON serialization | 14 // Configure the textboxes, allowing 200 characters for JSON serialization |
14 // and key length. | 15 // and key length. |
15 blacklist.maxlength = chrome.storage.sync.QUOTA_BYTES_PER_ITEM - 200; | 16 $('blacklist').maxlength = chrome.storage.sync.QUOTA_BYTES_PER_ITEM - 200; |
16 whitelist.maxlength = chrome.storage.sync.QUOTA_BYTES_PER_ITEM - 200; | 17 $('whitelist').maxlength = chrome.storage.sync.QUOTA_BYTES_PER_ITEM - 200; |
17 | 18 |
18 // Set event handlers. | 19 // Set event handlers. |
19 document.getElementById('done_button').onclick = function() { | 20 $('done-button').onclick = function() { |
20 chrome.storage.sync.set({ | 21 chrome.storage.sync.set({ |
21 // Split the lists into arrays at whitespace before saving. | 22 // Split the lists into arrays at whitespace before saving. |
22 blacklist: | 23 // TODO: Validate the items as URLs and display a warning in case of |
23 document.getElementById('blacklist').value.split(/\s+/), | 24 // errors. |
24 disableInApplets: document.getElementById('disableInApplets').checked, | 25 blacklist: $('blacklist').value.split(/\s+/), |
25 whitelist: | 26 disableInApplets: $('disableInApplets').checked, |
26 document.getElementById('whitelist').value.split(/\s+/) | 27 whitelist: $('whitelist').value.split(/\s+/) |
27 }, function() { | 28 }, function() { |
28 // One easy way to force an error for testing is to change "sync" to | 29 // One easy way to force an error for testing is to change "sync" to |
29 // "managed" in the chrome.storage.sync.set() call above. | 30 // "managed" in the chrome.storage.sync.set() call above. |
30 if (chrome.runtime.lastError) { | 31 if (chrome.runtime.lastError) { |
31 document.getElementById('error').textContent = | 32 $('error').textContent = |
32 chrome.i18n.getMessage('errorSaving', | 33 chrome.i18n.getMessage('errorSaving', |
33 chrome.runtime.lastError.message); | 34 chrome.runtime.lastError.message); |
34 } else { | 35 } else { |
35 window.close(); | 36 window.close(); |
36 } | 37 } |
37 }); | 38 }); |
38 }; | 39 }; |
39 | 40 |
40 document.getElementById('cancel_button').onclick = function() { | 41 $('disableInApplets').onchange = updateEnabledInputs; |
41 window.close(); | 42 $('cancel-button').onclick = window.close.bind(window); |
42 }; | 43 $('feedback-link').onclick = function() { |
43 | 44 sendFeedback(); |
44 document.getElementById('report_page').onclick = function() { | |
45 reportPage(); | |
46 }; | 45 }; |
47 | 46 |
48 // Load saved settings into the form fields. | 47 // Load saved settings into the form fields. |
49 chrome.storage.sync.get({ | 48 chrome.storage.sync.get({ |
50 blacklist: [], | 49 blacklist: [], |
51 disableInApplets: true, | 50 disableInApplets: true, |
52 whitelist: [] | 51 whitelist: [] |
53 }, function(items) { | 52 }, function(items) { |
54 blacklist.value = items.blacklist.join('\n'); | 53 $('blacklist').value = items.blacklist.join('\n'); |
55 checkbox.checked = items.disableInApplets; | 54 $('disableInApplets').checked = items.disableInApplets; |
56 whitelist.value = items.whitelist.join('\n'); | 55 $('whitelist').value = items.whitelist.join('\n'); |
| 56 |
| 57 updateEnabledInputs(); |
57 }); | 58 }); |
58 } | 59 } |
59 | 60 |
60 window.addEventListener('load', init, false); | 61 window.addEventListener('load', init); |
OLD | NEW |