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

Side by Side Diff: desktop-options.js

Issue 29578574: Issue 5632 - Use checkboxes for toggling acceptable ads (Closed)
Patch Set: Fixed the duplication Created Oct. 20, 2017, 6:56 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
« no previous file with comments | « desktop-options.html ('k') | skin/desktop-options.css » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 }); 552 });
553 } 553 }
554 554
555 function switchTab(id) 555 function switchTab(id)
556 { 556 {
557 location.hash = id; 557 location.hash = id;
558 } 558 }
559 559
560 function execAction(action, element) 560 function execAction(action, element)
561 { 561 {
562 if (element.getAttribute("aria-disabled") == "true")
563 return;
564
562 switch (action) 565 switch (action)
563 { 566 {
564 case "add-domain-exception": 567 case "add-domain-exception":
565 addWhitelistedDomain(); 568 addWhitelistedDomain();
566 break; 569 break;
567 case "add-language-subscription": 570 case "add-language-subscription":
568 addEnableSubscription(findParentData(element, "access", false)); 571 addEnableSubscription(findParentData(element, "access", false));
569 break; 572 break;
570 case "add-predefined-subscription": { 573 case "add-predefined-subscription": {
571 let dialog = E("dialog-content-predefined"); 574 let dialog = E("dialog-content-predefined");
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 () => 650 () =>
648 { 651 {
649 setCustomFiltersView("read"); 652 setCustomFiltersView("read");
650 }); 653 });
651 break; 654 break;
652 case "show-more-filters-section": 655 case "show-more-filters-section":
653 E("more-filters").setAttribute("aria-hidden", false); 656 E("more-filters").setAttribute("aria-hidden", false);
654 break; 657 break;
655 case "switch-acceptable-ads": 658 case "switch-acceptable-ads":
656 let value = element.value || element.dataset.value; 659 let value = element.value || element.dataset.value;
660 // User check the checkbox
661 let shouldCheck = element.getAttribute("aria-checked") != "true";
662 let installAcceptableAds = false;
663 let installAcceptableAdsPrivacy = false;
664 // Acceptable Ads checkbox clicked
665 if (value == "ads")
666 {
667 installAcceptableAds = shouldCheck;
668 }
669 // Privacy Friendly Acceptable Ads checkbox clicked
670 else
671 {
672 installAcceptableAdsPrivacy = shouldCheck;
673 installAcceptableAds = !shouldCheck;
674 }
675
657 browser.runtime.sendMessage({ 676 browser.runtime.sendMessage({
658 type: value == "privacy" ? "subscriptions.add" : 677 type: installAcceptableAds ? "subscriptions.add" :
678 "subscriptions.remove",
679 url: acceptableAdsUrl
680 });
681 browser.runtime.sendMessage({
682 type: installAcceptableAdsPrivacy ? "subscriptions.add" :
659 "subscriptions.remove", 683 "subscriptions.remove",
660 url: acceptableAdsPrivacyUrl 684 url: acceptableAdsPrivacyUrl
661 }); 685 });
662 browser.runtime.sendMessage({
663 type: value == "ads" ? "subscriptions.add" : "subscriptions.remove",
664 url: acceptableAdsUrl
665 });
666 break; 686 break;
667 case "switch-tab": 687 case "switch-tab":
668 switchTab(element.getAttribute("href").substr(1)); 688 switchTab(element.getAttribute("href").substr(1));
669 break; 689 break;
670 case "toggle-disable-subscription": 690 case "toggle-disable-subscription":
671 browser.runtime.sendMessage({ 691 browser.runtime.sendMessage({
672 type: "subscriptions.toggle", 692 type: "subscriptions.toggle",
673 keepInstalled: true, 693 keepInstalled: true,
674 url: findParentData(element, "access", false) 694 url: findParentData(element, "access", false)
675 }); 695 });
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 { 902 {
883 E("whitelisting-add-button").disabled = !e.target.value; 903 E("whitelisting-add-button").disabled = !e.target.value;
884 }, false); 904 }, false);
885 905
886 getDocLink("contribute", (link) => 906 getDocLink("contribute", (link) =>
887 { 907 {
888 E("contribute").href = link; 908 E("contribute").href = link;
889 }); 909 });
890 getDocLink("acceptable_ads_criteria", (link) => 910 getDocLink("acceptable_ads_criteria", (link) =>
891 { 911 {
892 setLinks("enable-aa-description", link); 912 setLinks("enable-acceptable-ads-description", link);
913 });
914 getDocLink("privacy_friendly_ads", (link) =>
915 {
916 E("enable-acceptable-ads-privacy-description").href = link;
893 }); 917 });
894 getDocLink("adblock_plus_{browser}_dnt", url => 918 getDocLink("adblock_plus_{browser}_dnt", url =>
895 { 919 {
896 setLinks("dnt", url); 920 setLinks("dnt", url);
897 }); 921 });
898 922
899 // Advanced tab 923 // Advanced tab
900 let customize = document.querySelectorAll("#customize li[data-pref]"); 924 let customize = document.querySelectorAll("#customize li[data-pref]");
901 customize = Array.prototype.map.call(customize, (checkbox) => 925 customize = Array.prototype.map.call(customize, (checkbox) =>
902 { 926 {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 } 1051 }
1028 1052
1029 function hideNotification() 1053 function hideNotification()
1030 { 1054 {
1031 E("notification").setAttribute("aria-hidden", true); 1055 E("notification").setAttribute("aria-hidden", true);
1032 E("notification-text").textContent = ""; 1056 E("notification-text").textContent = "";
1033 } 1057 }
1034 1058
1035 function setAcceptableAds() 1059 function setAcceptableAds()
1036 { 1060 {
1037 let option = "none"; 1061 let acceptableAdsForm = E("acceptable-ads");
1038 document.forms["acceptable-ads"].classList.remove("show-dnt-notification"); 1062 let acceptableAds = E("acceptable-ads-allow");
1063 let acceptableAdsPrivacy = E("acceptable-ads-privacy-allow");
1064 acceptableAdsForm.classList.remove("show-dnt-notification");
1065 acceptableAds.setAttribute("aria-checked", false);
1066 acceptableAdsPrivacy.setAttribute("aria-checked", false);
1067 acceptableAdsPrivacy.setAttribute("tabindex", 0);
1039 if (acceptableAdsUrl in subscriptionsMap) 1068 if (acceptableAdsUrl in subscriptionsMap)
1040 { 1069 {
1041 option = "ads"; 1070 acceptableAds.setAttribute("aria-checked", true);
1071 acceptableAdsPrivacy.setAttribute("aria-disabled", false);
1042 } 1072 }
1043 else if (acceptableAdsPrivacyUrl in subscriptionsMap) 1073 else if (acceptableAdsPrivacyUrl in subscriptionsMap)
1044 { 1074 {
1045 option = "privacy"; 1075 acceptableAds.setAttribute("aria-checked", true);
1076 acceptableAdsPrivacy.setAttribute("aria-checked", true);
1077 acceptableAdsPrivacy.setAttribute("aria-disabled", false);
1046 1078
1047 if (!navigator.doNotTrack) 1079 if (navigator.doNotTrack != 1)
1048 document.forms["acceptable-ads"].classList.add("show-dnt-notification"); 1080 acceptableAdsForm.classList.add("show-dnt-notification");
1049 } 1081 }
1050 document.forms["acceptable-ads"]["acceptable-ads"].value = option; 1082 else
1083 {
1084 // Using aria-disabled in order to keep the focus
1085 acceptableAdsPrivacy.setAttribute("aria-disabled", true);
1086 acceptableAdsPrivacy.setAttribute("tabindex", -1);
1087 }
1051 } 1088 }
1052 1089
1053 function isAcceptableAds(url) 1090 function isAcceptableAds(url)
1054 { 1091 {
1055 return url == acceptableAdsUrl || url == acceptableAdsPrivacyUrl; 1092 return url == acceptableAdsUrl || url == acceptableAdsPrivacyUrl;
1056 } 1093 }
1057 1094
1058 function populateLists() 1095 function populateLists()
1059 { 1096 {
1060 subscriptionsMap = Object.create(null); 1097 subscriptionsMap = Object.create(null);
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
1380 }); 1417 });
1381 browser.runtime.sendMessage({ 1418 browser.runtime.sendMessage({
1382 type: "subscriptions.listen", 1419 type: "subscriptions.listen",
1383 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1420 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1384 "title", "downloadStatus", "downloading"] 1421 "title", "downloadStatus", "downloading"]
1385 }); 1422 });
1386 1423
1387 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1424 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1388 window.addEventListener("hashchange", onHashChange, false); 1425 window.addEventListener("hashchange", onHashChange, false);
1389 } 1426 }
OLDNEW
« no previous file with comments | « desktop-options.html ('k') | skin/desktop-options.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld