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: Fixed tabulation Created Aug. 23, 2017, 1:31 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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 { 519 {
520 ext.backgroundPage.sendMessage(message, (errors) => 520 ext.backgroundPage.sendMessage(message, (errors) =>
521 { 521 {
522 if (errors.length > 0) 522 if (errors.length > 0)
523 alert(errors.join("\n")); 523 alert(errors.join("\n"));
524 else if (onSuccess) 524 else if (onSuccess)
525 onSuccess(); 525 onSuccess();
526 }); 526 });
527 } 527 }
528 528
529 function openDocLink(id)
530 {
531 getDocLink(id, (link) =>
532 {
533 if (id == "share-general")
534 openSharePopup(link);
535 else
536 location.href = link;
537 });
538 }
539
540 function switchTab(id) 529 function switchTab(id)
541 { 530 {
542 location.hash = id; 531 location.hash = id;
543 } 532 }
544 533
545 function execAction(action, element) 534 function execAction(action, element)
546 { 535 {
547 switch (action) 536 switch (action)
548 { 537 {
549 case "add-domain-exception": 538 case "add-domain-exception":
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 let listItem = findParentData(element, "access", true); 587 let listItem = findParentData(element, "access", true);
599 if (listItem && !listItem.classList.contains("show-context-menu")) 588 if (listItem && !listItem.classList.contains("show-context-menu"))
600 listItem.classList.add("show-context-menu"); 589 listItem.classList.add("show-context-menu");
601 break; 590 break;
602 } 591 }
603 case "open-dialog": { 592 case "open-dialog": {
604 let dialog = findParentData(element, "dialog", false); 593 let dialog = findParentData(element, "dialog", false);
605 openDialog(dialog); 594 openDialog(dialog);
606 break; 595 break;
607 } 596 }
608 case "open-doclink": {
609 let doclink = findParentData(element, "doclink", false);
610 openDocLink(doclink);
611 break;
612 }
613 case "remove-filter": 597 case "remove-filter":
614 ext.backgroundPage.sendMessage({ 598 ext.backgroundPage.sendMessage({
615 type: "filters.remove", 599 type: "filters.remove",
616 text: findParentData(element, "access", false) 600 text: findParentData(element, "access", false)
617 }); 601 });
618 break; 602 break;
619 case "remove-subscription": 603 case "remove-subscription":
620 ext.backgroundPage.sendMessage({ 604 ext.backgroundPage.sendMessage({
621 type: "subscriptions.remove", 605 type: "subscriptions.remove",
622 url: findParentData(element, "access", false) 606 url: findParentData(element, "access", false)
(...skipping 16 matching lines...) Expand all
639 type: value == "privacy" ? "subscriptions.add" : 623 type: value == "privacy" ? "subscriptions.add" :
640 "subscriptions.remove", 624 "subscriptions.remove",
641 url: acceptableAdsPrivacyUrl 625 url: acceptableAdsPrivacyUrl
642 }); 626 });
643 ext.backgroundPage.sendMessage({ 627 ext.backgroundPage.sendMessage({
644 type: value == "ads" ? "subscriptions.add" : "subscriptions.remove", 628 type: value == "ads" ? "subscriptions.add" : "subscriptions.remove",
645 url: acceptableAdsUrl 629 url: acceptableAdsUrl
646 }); 630 });
647 break; 631 break;
648 case "switch-tab": 632 case "switch-tab":
649 let tabId = findParentData(element, "tab", false); 633 switchTab(element.getAttribute("href").substr(1));
650 switchTab(tabId);
651 break; 634 break;
652 case "toggle-disable-subscription": 635 case "toggle-disable-subscription":
653 ext.backgroundPage.sendMessage({ 636 ext.backgroundPage.sendMessage({
654 type: "subscriptions.toggle", 637 type: "subscriptions.toggle",
655 keepInstalled: true, 638 keepInstalled: true,
656 url: findParentData(element, "access", false) 639 url: findParentData(element, "access", false)
657 }); 640 });
658 break; 641 break;
659 case "toggle-pref": 642 case "toggle-pref":
660 ext.backgroundPage.sendMessage({ 643 ext.backgroundPage.sendMessage({
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 let container = findParentData(element, "action", true); 736 let container = findParentData(element, "action", true);
754 if (!container || !container.hasAttribute("data-keys")) 737 if (!container || !container.hasAttribute("data-keys"))
755 return; 738 return;
756 739
757 let keys = container.getAttribute("data-keys").split(" "); 740 let keys = container.getAttribute("data-keys").split(" ");
758 if (keys.indexOf(key) < 0) 741 if (keys.indexOf(key) < 0)
759 return; 742 return;
760 743
761 if (element.getAttribute("role") == "tab") 744 if (element.getAttribute("role") == "tab")
762 { 745 {
746 let parent = element.parentElement;
763 if (key == "ArrowLeft" || key == "ArrowUp") 747 if (key == "ArrowLeft" || key == "ArrowUp")
764 element = element.previousElementSibling || container.lastElementChild; 748 parent = parent.previousElementSibling || container.lastElementChild;
765 else if (key == "ArrowRight" || key == "ArrowDown") 749 else if (key == "ArrowRight" || key == "ArrowDown")
766 element = element.nextElementSibling || container.firstElementChild; 750 parent = parent.nextElementSibling || container.firstElementChild;
751 element = parent.firstElementChild;
767 } 752 }
768 753
769 let actions = container.getAttribute("data-action").split(","); 754 let actions = container.getAttribute("data-action").split(",");
770 for (let action of actions) 755 for (let action of actions)
771 { 756 {
772 execAction(action, element); 757 execAction(action, element);
773 } 758 }
774 } 759 }
775 760
776 function selectTabItem(tabId, container, focus) 761 function selectTabItem(tabId, container, focus)
777 { 762 {
778 // Show tab content 763 // Show tab content
779 document.body.setAttribute("data-tab", tabId); 764 document.body.setAttribute("data-tab", tabId);
780 765
781 // Select tab 766 // Select tab
782 let tabList = container.querySelector("[role='tablist']"); 767 let tabList = container.querySelector("[role='tablist']");
783 if (!tabList) 768 if (!tabList)
784 return null; 769 return null;
785 770
786 let previousTab = tabList.querySelector("[aria-selected]"); 771 let previousTab = tabList.querySelector("[aria-selected]");
787 previousTab.removeAttribute("aria-selected"); 772 previousTab.removeAttribute("aria-selected");
788 previousTab.setAttribute("tabindex", -1);
789 773
790 let tab = tabList.querySelector("li[data-tab='" + tabId + "']"); 774 let tab = tabList.querySelector("a[href='#" + tabId + "']");
791 tab.setAttribute("aria-selected", true); 775 tab.setAttribute("aria-selected", true);
792 tab.setAttribute("tabindex", 0);
793 776
794 let tabContentId = tab.getAttribute("aria-controls"); 777 let tabContentId = tab.getAttribute("aria-controls");
795 let tabContent = document.getElementById(tabContentId); 778 let tabContent = document.getElementById(tabContentId);
796 779
797 if (tab && focus) 780 if (tab && focus)
798 tab.focus(); 781 tab.focus();
799 782
800 return tabContent; 783 return tabContent;
801 } 784 }
802 785
(...skipping 19 matching lines...) Expand all
822 { 805 {
823 populateLists(); 806 populateLists();
824 807
825 // Initialize navigation sidebar 808 // Initialize navigation sidebar
826 ext.backgroundPage.sendMessage({ 809 ext.backgroundPage.sendMessage({
827 type: "app.get", 810 type: "app.get",
828 what: "addonVersion" 811 what: "addonVersion"
829 }, 812 },
830 (addonVersion) => 813 (addonVersion) =>
831 { 814 {
832 E("abp-version").textContent = addonVersion; 815 E("abp-version").textContent = getMessage("options_dialog_about_version",
833 }); 816 [addonVersion]);
834 getDocLink("releases", (link) =>
835 {
836 E("link-version").setAttribute("href", link);
837 }); 817 });
838 818
839 updateShareLink();
840 updateTooltips(); 819 updateTooltips();
841 820
842 // Initialize interactive UI elements 821 // Initialize interactive UI elements
843 document.body.addEventListener("click", onClick, false); 822 document.body.addEventListener("click", onClick, false);
844 document.body.addEventListener("keyup", onKeyUp, false); 823 document.body.addEventListener("keyup", onKeyUp, false);
845 let exampleValue = getMessage("options_whitelist_placeholder_example", 824 let exampleValue = getMessage("options_whitelist_placeholder_example",
846 ["www.example.com"]); 825 ["www.example.com"]);
847 E("whitelisting-textbox").setAttribute("placeholder", exampleValue); 826 E("whitelisting-textbox").setAttribute("placeholder", exampleValue);
848 E("whitelisting-textbox").addEventListener("keyup", (e) => 827 E("whitelisting-textbox").addEventListener("keyup", (e) =>
849 { 828 {
850 E("whitelisting-add-button").disabled = !e.target.value; 829 E("whitelisting-add-button").disabled = !e.target.value;
851 }, false); 830 }, false);
852 831
832
833 getDocLink("contribute", (link) =>
834 {
835 E("contribute").href = link;
836 });
853 getDocLink("acceptable_ads_criteria", (link) => 837 getDocLink("acceptable_ads_criteria", (link) =>
854 { 838 {
855 setLinks("enable-aa-description", link); 839 setLinks("enable-aa-description", link);
856 }); 840 });
857 841
858 // Advanced tab 842 // Advanced tab
859 let customize = document.querySelectorAll("#customize li[data-pref]"); 843 let customize = document.querySelectorAll("#customize li[data-pref]");
860 customize = Array.prototype.map.call(customize, (checkbox) => 844 customize = Array.prototype.map.call(customize, (checkbox) =>
861 { 845 {
862 return checkbox.getAttribute("data-pref"); 846 return checkbox.getAttribute("data-pref");
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 ext.backgroundPage.sendMessage(message); 1113 ext.backgroundPage.sendMessage(message);
1130 } 1114 }
1131 1115
1132 function onFilterMessage(action, filter) 1116 function onFilterMessage(action, filter)
1133 { 1117 {
1134 switch (action) 1118 switch (action)
1135 { 1119 {
1136 case "added": 1120 case "added":
1137 filter[timestampUI] = Date.now(); 1121 filter[timestampUI] = Date.now();
1138 updateFilter(filter); 1122 updateFilter(filter);
1139 updateShareLink();
1140 break; 1123 break;
1141 case "loaded": 1124 case "loaded":
1142 populateLists(); 1125 populateLists();
1143 break; 1126 break;
1144 case "removed": 1127 case "removed":
1145 let knownFilter = filtersMap[filter.text]; 1128 let knownFilter = filtersMap[filter.text];
1146 if (whitelistedDomainRegexp.test(knownFilter.text)) 1129 if (whitelistedDomainRegexp.test(knownFilter.text))
1147 collections.whitelist.removeItem(knownFilter); 1130 collections.whitelist.removeItem(knownFilter);
1148 else 1131 else
1149 removeCustomFilter(filter.text); 1132 removeCustomFilter(filter.text);
1150 1133
1151 delete filtersMap[filter.text]; 1134 delete filtersMap[filter.text];
1152 updateShareLink();
1153 break; 1135 break;
1154 } 1136 }
1155 } 1137 }
1156 1138
1157 function onSubscriptionMessage(action, subscription) 1139 function onSubscriptionMessage(action, subscription)
1158 { 1140 {
1159 if (subscription.url in subscriptionsMap) 1141 if (subscription.url in subscriptionsMap)
1160 { 1142 {
1161 let knownSubscription = subscriptionsMap[subscription.url]; 1143 let knownSubscription = subscriptionsMap[subscription.url];
1162 for (let property in subscription) 1144 for (let property in subscription)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 } 1188 }
1207 else 1189 else
1208 { 1190 {
1209 collections.custom.removeItem(subscription); 1191 collections.custom.removeItem(subscription);
1210 } 1192 }
1211 } 1193 }
1212 collections.filterLists.removeItem(subscription); 1194 collections.filterLists.removeItem(subscription);
1213 break; 1195 break;
1214 } 1196 }
1215 1197
1216 updateShareLink();
1217 } 1198 }
1218 1199
1219 function hidePref(key, value) 1200 function hidePref(key, value)
1220 { 1201 {
1221 let element = document.querySelector("[data-pref='" + key + "']"); 1202 let element = document.querySelector("[data-pref='" + key + "']");
1222 if (element) 1203 if (element)
1223 element.setAttribute("aria-hidden", value); 1204 element.setAttribute("aria-hidden", value);
1224 } 1205 }
1225 1206
1226 function getPref(key, callback) 1207 function getPref(key, callback)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 break; 1248 break;
1268 } 1249 }
1269 1250
1270 let checkbox = document.querySelector( 1251 let checkbox = document.querySelector(
1271 "[data-pref='" + key + "'] button[role='checkbox']" 1252 "[data-pref='" + key + "'] button[role='checkbox']"
1272 ); 1253 );
1273 if (checkbox) 1254 if (checkbox)
1274 checkbox.setAttribute("aria-checked", value); 1255 checkbox.setAttribute("aria-checked", value);
1275 } 1256 }
1276 1257
1277 function updateShareLink()
1278 {
1279 let shareResources = [
1280 "https://facebook.com/plugins/like.php?",
1281 "https://platform.twitter.com/widgets/",
1282 "https://apis.google.com/se/0/_/+1/fastbutton?"
1283 ];
1284 let isAnyBlocked = false;
1285 let checksRemaining = shareResources.length;
1286
1287 function onResult(isBlocked)
1288 {
1289 isAnyBlocked |= isBlocked;
1290 if (!--checksRemaining)
1291 {
1292 // Hide the share tab if a script on the share page would be blocked
1293 E("tab-share").hidden = isAnyBlocked;
1294 }
1295 }
1296
1297 for (let sharedResource of shareResources)
1298 checkShareResource(sharedResource, onResult);
1299 }
1300
1301 function updateTooltips() 1258 function updateTooltips()
1302 { 1259 {
1303 let anchors = document.querySelectorAll(":not(.tooltip) > [data-tooltip]"); 1260 let anchors = document.querySelectorAll(":not(.tooltip) > [data-tooltip]");
1304 for (let anchor of anchors) 1261 for (let anchor of anchors)
1305 { 1262 {
1306 let id = anchor.getAttribute("data-tooltip"); 1263 let id = anchor.getAttribute("data-tooltip");
1307 1264
1308 let wrapper = document.createElement("div"); 1265 let wrapper = document.createElement("div");
1309 wrapper.className = "tooltip"; 1266 wrapper.className = "tooltip";
1310 anchor.parentNode.replaceChild(wrapper, anchor); 1267 anchor.parentNode.replaceChild(wrapper, anchor);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1367 }); 1324 });
1368 ext.backgroundPage.sendMessage({ 1325 ext.backgroundPage.sendMessage({
1369 type: "subscriptions.listen", 1326 type: "subscriptions.listen",
1370 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1327 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1371 "title", "downloadStatus", "downloading"] 1328 "title", "downloadStatus", "downloading"]
1372 }); 1329 });
1373 1330
1374 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1331 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1375 window.addEventListener("hashchange", onHashChange, false); 1332 window.addEventListener("hashchange", onHashChange, false);
1376 } 1333 }
OLDNEW

Powered by Google App Engine
This is Rietveld