Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: new-options.js

Issue 29502647: Issue 5482 - Sidebar and about ABP dialog (Closed)
Patch Set: Addressed comments Created Aug. 23, 2017, 12:23 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 { 543 {
544 ext.backgroundPage.sendMessage(message, (errors) => 544 ext.backgroundPage.sendMessage(message, (errors) =>
545 { 545 {
546 if (errors.length > 0) 546 if (errors.length > 0)
547 alert(errors.join("\n")); 547 alert(errors.join("\n"));
548 else if (onSuccess) 548 else if (onSuccess)
549 onSuccess(); 549 onSuccess();
550 }); 550 });
551 } 551 }
552 552
553 function openDocLink(id)
554 {
555 getDocLink(id, (link) =>
556 {
557 if (id == "share-general")
558 openSharePopup(link);
559 else
560 location.href = link;
561 });
562 }
563
564 function switchTab(id) 553 function switchTab(id)
565 { 554 {
566 location.hash = id; 555 location.hash = id;
567 } 556 }
568 557
569 function execAction(action, element) 558 function execAction(action, element)
570 { 559 {
571 switch (action) 560 switch (action)
572 { 561 {
573 case "add-domain-exception": 562 case "add-domain-exception":
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 let listItem = findParentData(element, "access", true); 634 let listItem = findParentData(element, "access", true);
646 if (listItem && !listItem.classList.contains("show-context-menu")) 635 if (listItem && !listItem.classList.contains("show-context-menu"))
647 listItem.classList.add("show-context-menu"); 636 listItem.classList.add("show-context-menu");
648 break; 637 break;
649 } 638 }
650 case "open-dialog": { 639 case "open-dialog": {
651 let dialog = findParentData(element, "dialog", false); 640 let dialog = findParentData(element, "dialog", false);
652 openDialog(dialog); 641 openDialog(dialog);
653 break; 642 break;
654 } 643 }
655 case "open-doclink": {
656 let doclink = findParentData(element, "doclink", false);
657 openDocLink(doclink);
658 break;
659 }
660 case "remove-filter": 644 case "remove-filter":
661 ext.backgroundPage.sendMessage({ 645 ext.backgroundPage.sendMessage({
662 type: "filters.remove", 646 type: "filters.remove",
663 text: findParentData(element, "access", false) 647 text: findParentData(element, "access", false)
664 }); 648 });
665 break; 649 break;
666 case "remove-subscription": 650 case "remove-subscription":
667 ext.backgroundPage.sendMessage({ 651 ext.backgroundPage.sendMessage({
668 type: "subscriptions.remove", 652 type: "subscriptions.remove",
669 url: findParentData(element, "access", false) 653 url: findParentData(element, "access", false)
670 }); 654 });
671 break; 655 break;
672 case "save-change-subscription": 656 case "save-change-subscription":
673 subscriptionToChange = findParentData(element, "access", false); 657 subscriptionToChange = findParentData(element, "access", false);
674 break; 658 break;
675 case "save-custom-filters": 659 case "save-custom-filters":
676 sendMessageHandleErrors({ 660 sendMessageHandleErrors({
677 type: "filters.importRaw", 661 type: "filters.importRaw",
678 text: E("custom-filters-raw").value, 662 text: E("custom-filters-raw").value,
679 removeExisting: true 663 removeExisting: true
680 }, 664 },
681 () => 665 () =>
682 { 666 {
683 setCustomFiltersView("read"); 667 setCustomFiltersView("read");
684 }); 668 });
685 break; 669 break;
686 case "switch-tab": 670 case "switch-tab":
687 let tabId = findParentData(element, "tab", false); 671 switchTab(element.getAttribute("href").substr(1));
688 switchTab(tabId);
689 break; 672 break;
690 case "toggle-disable-subscription": 673 case "toggle-disable-subscription":
691 ext.backgroundPage.sendMessage({ 674 ext.backgroundPage.sendMessage({
692 type: "subscriptions.toggle", 675 type: "subscriptions.toggle",
693 keepInstalled: true, 676 keepInstalled: true,
694 url: findParentData(element, "access", false) 677 url: findParentData(element, "access", false)
695 }); 678 });
696 break; 679 break;
697 case "toggle-pref": 680 case "toggle-pref":
698 ext.backgroundPage.sendMessage({ 681 ext.backgroundPage.sendMessage({
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 let container = findParentData(element, "action", true); 774 let container = findParentData(element, "action", true);
792 if (!container || !container.hasAttribute("data-keys")) 775 if (!container || !container.hasAttribute("data-keys"))
793 return; 776 return;
794 777
795 let keys = container.getAttribute("data-keys").split(" "); 778 let keys = container.getAttribute("data-keys").split(" ");
796 if (keys.indexOf(key) < 0) 779 if (keys.indexOf(key) < 0)
797 return; 780 return;
798 781
799 if (element.getAttribute("role") == "tab") 782 if (element.getAttribute("role") == "tab")
800 { 783 {
784 let parent = element.parentElement;
801 if (key == "ArrowLeft" || key == "ArrowUp") 785 if (key == "ArrowLeft" || key == "ArrowUp")
802 element = element.previousElementSibling || container.lastElementChild; 786 parent = parent.previousElementSibling || container.lastElementChild;
803 else if (key == "ArrowRight" || key == "ArrowDown") 787 else if (key == "ArrowRight" || key == "ArrowDown")
804 element = element.nextElementSibling || container.firstElementChild; 788 parent = parent.nextElementSibling || container.firstElementChild;
789 element = parent.firstElementChild;
805 } 790 }
806 791
807 let actions = container.getAttribute("data-action").split(","); 792 let actions = container.getAttribute("data-action").split(",");
808 for (let action of actions) 793 for (let action of actions)
809 { 794 {
810 execAction(action, element); 795 execAction(action, element);
811 } 796 }
812 } 797 }
813 798
814 function selectTabItem(tabId, container, focus) 799 function selectTabItem(tabId, container, focus)
815 { 800 {
816 // Show tab content 801 // Show tab content
817 document.body.setAttribute("data-tab", tabId); 802 document.body.setAttribute("data-tab", tabId);
818 803
819 // Select tab 804 // Select tab
820 let tabList = container.querySelector("[role='tablist']"); 805 let tabList = container.querySelector("[role='tablist']");
821 if (!tabList) 806 if (!tabList)
822 return null; 807 return null;
823 808
824 let previousTab = tabList.querySelector("[aria-selected]"); 809 let previousTab = tabList.querySelector("[aria-selected]");
825 previousTab.removeAttribute("aria-selected"); 810 previousTab.removeAttribute("aria-selected");
826 previousTab.setAttribute("tabindex", -1);
827 811
828 let tab = tabList.querySelector("li[data-tab='" + tabId + "']"); 812 let tab = tabList.querySelector("a[href='#" + tabId + "']");
829 tab.setAttribute("aria-selected", true); 813 tab.setAttribute("aria-selected", true);
830 tab.setAttribute("tabindex", 0);
831 814
832 let tabContentId = tab.getAttribute("aria-controls"); 815 let tabContentId = tab.getAttribute("aria-controls");
833 let tabContent = document.getElementById(tabContentId); 816 let tabContent = document.getElementById(tabContentId);
834 817
835 if (tab && focus) 818 if (tab && focus)
836 tab.focus(); 819 tab.focus();
837 820
838 return tabContent; 821 return tabContent;
839 } 822 }
840 823
(...skipping 19 matching lines...) Expand all
860 { 843 {
861 populateLists(); 844 populateLists();
862 845
863 // Initialize navigation sidebar 846 // Initialize navigation sidebar
864 ext.backgroundPage.sendMessage({ 847 ext.backgroundPage.sendMessage({
865 type: "app.get", 848 type: "app.get",
866 what: "addonVersion" 849 what: "addonVersion"
867 }, 850 },
868 (addonVersion) => 851 (addonVersion) =>
869 { 852 {
870 E("abp-version").textContent = addonVersion; 853 E("abp-version").textContent = getMessage("options_dialog_about_version",
871 }); 854 [addonVersion]);
872 getDocLink("releases", (link) =>
873 {
874 E("link-version").setAttribute("href", link);
875 }); 855 });
876 856
877 updateShareLink();
878 updateTooltips(); 857 updateTooltips();
879 858
880 // Initialize interactive UI elements 859 // Initialize interactive UI elements
881 document.body.addEventListener("click", onClick, false); 860 document.body.addEventListener("click", onClick, false);
882 document.body.addEventListener("keyup", onKeyUp, false); 861 document.body.addEventListener("keyup", onKeyUp, false);
883 let exampleValue = getMessage("options_whitelist_placeholder_example", 862 let exampleValue = getMessage("options_whitelist_placeholder_example",
884 ["www.example.com"]); 863 ["www.example.com"]);
885 E("whitelisting-textbox").setAttribute("placeholder", exampleValue); 864 E("whitelisting-textbox").setAttribute("placeholder", exampleValue);
886 E("whitelisting-textbox").addEventListener("keyup", (e) => 865 E("whitelisting-textbox").addEventListener("keyup", (e) =>
887 { 866 {
888 E("whitelisting-add-button").disabled = !e.target.value; 867 E("whitelisting-add-button").disabled = !e.target.value;
889 }, false); 868 }, false);
890 869
870
871 getDocLink("contribute", (link) =>
872 {
873 E("contribute").href = link;
874 });
891 getDocLink("acceptable_ads_criteria", (link) => 875 getDocLink("acceptable_ads_criteria", (link) =>
892 { 876 {
893 setLinks("enable-aa-description", link); 877 setLinks("enable-aa-description", link);
894 }); 878 });
895 879
896 // Advanced tab 880 // Advanced tab
897 let customize = document.querySelectorAll("#customize li[data-pref]"); 881 let customize = document.querySelectorAll("#customize li[data-pref]");
898 customize = Array.prototype.map.call(customize, (checkbox) => 882 customize = Array.prototype.map.call(customize, (checkbox) =>
899 { 883 {
900 return checkbox.getAttribute("data-pref"); 884 return checkbox.getAttribute("data-pref");
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 ext.backgroundPage.sendMessage(message); 1140 ext.backgroundPage.sendMessage(message);
1157 } 1141 }
1158 1142
1159 function onFilterMessage(action, filter) 1143 function onFilterMessage(action, filter)
1160 { 1144 {
1161 switch (action) 1145 switch (action)
1162 { 1146 {
1163 case "added": 1147 case "added":
1164 filter[timestampUI] = Date.now(); 1148 filter[timestampUI] = Date.now();
1165 updateFilter(filter); 1149 updateFilter(filter);
1166 updateShareLink();
1167 break; 1150 break;
1168 case "loaded": 1151 case "loaded":
1169 populateLists(); 1152 populateLists();
1170 break; 1153 break;
1171 case "removed": 1154 case "removed":
1172 let knownFilter = filtersMap[filter.text]; 1155 let knownFilter = filtersMap[filter.text];
1173 if (whitelistedDomainRegexp.test(knownFilter.text)) 1156 if (whitelistedDomainRegexp.test(knownFilter.text))
1174 collections.whitelist.removeItem(knownFilter); 1157 collections.whitelist.removeItem(knownFilter);
1175 else 1158 else
1176 removeCustomFilter(filter.text); 1159 removeCustomFilter(filter.text);
1177 1160
1178 delete filtersMap[filter.text]; 1161 delete filtersMap[filter.text];
1179 updateShareLink();
1180 break; 1162 break;
1181 } 1163 }
1182 } 1164 }
1183 1165
1184 function onSubscriptionMessage(action, subscription) 1166 function onSubscriptionMessage(action, subscription)
1185 { 1167 {
1186 if (subscription.url in subscriptionsMap) 1168 if (subscription.url in subscriptionsMap)
1187 { 1169 {
1188 let knownSubscription = subscriptionsMap[subscription.url]; 1170 let knownSubscription = subscriptionsMap[subscription.url];
1189 for (let property in subscription) 1171 for (let property in subscription)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 } 1219 }
1238 else 1220 else
1239 { 1221 {
1240 collections.custom.removeItem(subscription); 1222 collections.custom.removeItem(subscription);
1241 delete subscriptionsMap[subscription.url]; 1223 delete subscriptionsMap[subscription.url];
1242 } 1224 }
1243 collections.filterLists.removeItem(subscription); 1225 collections.filterLists.removeItem(subscription);
1244 break; 1226 break;
1245 } 1227 }
1246 1228
1247 updateShareLink();
1248 } 1229 }
1249 1230
1250 function hidePref(key, value) 1231 function hidePref(key, value)
1251 { 1232 {
1252 let element = document.querySelector("[data-pref='" + key + "']"); 1233 let element = document.querySelector("[data-pref='" + key + "']");
1253 if (element) 1234 if (element)
1254 element.setAttribute("aria-hidden", value); 1235 element.setAttribute("aria-hidden", value);
1255 } 1236 }
1256 1237
1257 function getPref(key, callback) 1238 function getPref(key, callback)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1298 break; 1279 break;
1299 } 1280 }
1300 1281
1301 let checkbox = document.querySelector( 1282 let checkbox = document.querySelector(
1302 "[data-pref='" + key + "'] button[role='checkbox']" 1283 "[data-pref='" + key + "'] button[role='checkbox']"
1303 ); 1284 );
1304 if (checkbox) 1285 if (checkbox)
1305 checkbox.setAttribute("aria-checked", value); 1286 checkbox.setAttribute("aria-checked", value);
1306 } 1287 }
1307 1288
1308 function updateShareLink()
1309 {
1310 let shareResources = [
1311 "https://facebook.com/plugins/like.php?",
1312 "https://platform.twitter.com/widgets/",
1313 "https://apis.google.com/se/0/_/+1/fastbutton?"
1314 ];
1315 let isAnyBlocked = false;
1316 let checksRemaining = shareResources.length;
1317
1318 function onResult(isBlocked)
1319 {
1320 isAnyBlocked |= isBlocked;
1321 if (!--checksRemaining)
1322 {
1323 // Hide the share tab if a script on the share page would be blocked
1324 E("tab-share").hidden = isAnyBlocked;
1325 }
1326 }
1327
1328 for (let sharedResource of shareResources)
1329 checkShareResource(sharedResource, onResult);
1330 }
1331
1332 function getMessages(id) 1289 function getMessages(id)
1333 { 1290 {
1334 let messages = []; 1291 let messages = [];
1335 for (let i = 1; true; i++) 1292 for (let i = 1; true; i++)
1336 { 1293 {
1337 let message = ext.i18n.getMessage(id + "_" + i); 1294 let message = ext.i18n.getMessage(id + "_" + i);
1338 if (!message) 1295 if (!message)
1339 break; 1296 break;
1340 1297
1341 messages.push(message); 1298 messages.push(message);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1448 }); 1405 });
1449 ext.backgroundPage.sendMessage({ 1406 ext.backgroundPage.sendMessage({
1450 type: "subscriptions.listen", 1407 type: "subscriptions.listen",
1451 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1408 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1452 "title", "downloadStatus", "downloading"] 1409 "title", "downloadStatus", "downloading"]
1453 }); 1410 });
1454 1411
1455 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1412 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1456 window.addEventListener("hashchange", onHashChange, false); 1413 window.addEventListener("hashchange", onHashChange, false);
1457 } 1414 }
OLDNEW
« no previous file with comments | « new-options.html ('k') | skin/abp-logo.svg » ('j') | skin/new-options.css » ('J')

Powered by Google App Engine
This is Rietveld