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

Delta Between Two Patch Sets: desktop-options.js

Issue 29578574: Issue 5632 - Use checkboxes for toggling acceptable ads (Closed)
Left Patch Set: Rebased Created Oct. 17, 2017, 3:59 p.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « desktop-options.html ('k') | skin/desktop-options.css » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 }, 649 },
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 isChecked = element.getAttribute("aria-checked") == "true";
657 let value = element.value || element.dataset.value; 659 let value = element.value || element.dataset.value;
658 let isAcceptableAds = value == "ads"; 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 }
659 675
660 browser.runtime.sendMessage({ 676 browser.runtime.sendMessage({
661 type: isAcceptableAds != isChecked ? "subscriptions.add" : 677 type: installAcceptableAds ? "subscriptions.add" :
662 "subscriptions.remove", 678 "subscriptions.remove",
663 url: acceptableAdsUrl 679 url: acceptableAdsUrl
664 }); 680 });
665 browser.runtime.sendMessage({ 681 browser.runtime.sendMessage({
666 type: isAcceptableAds || isChecked ? "subscriptions.remove" : 682 type: installAcceptableAdsPrivacy ? "subscriptions.add" :
667 "subscriptions.add", 683 "subscriptions.remove",
668 url: acceptableAdsPrivacyUrl 684 url: acceptableAdsPrivacyUrl
669 }); 685 });
670 break; 686 break;
671 case "switch-tab": 687 case "switch-tab":
672 switchTab(element.getAttribute("href").substr(1)); 688 switchTab(element.getAttribute("href").substr(1));
673 break; 689 break;
674 case "toggle-disable-subscription": 690 case "toggle-disable-subscription":
675 browser.runtime.sendMessage({ 691 browser.runtime.sendMessage({
676 type: "subscriptions.toggle", 692 type: "subscriptions.toggle",
677 keepInstalled: true, 693 keepInstalled: true,
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 getDocLink("contribute", (link) => 906 getDocLink("contribute", (link) =>
891 { 907 {
892 E("contribute").href = link; 908 E("contribute").href = link;
893 }); 909 });
894 getDocLink("acceptable_ads_criteria", (link) => 910 getDocLink("acceptable_ads_criteria", (link) =>
895 { 911 {
896 setLinks("enable-acceptable-ads-description", link); 912 setLinks("enable-acceptable-ads-description", link);
897 }); 913 });
898 getDocLink("privacy_friendly_ads", (link) => 914 getDocLink("privacy_friendly_ads", (link) =>
899 { 915 {
900 setLinks("enable-acceptable-ads-privacy-description", link); 916 E("enable-acceptable-ads-privacy-description").href = link;
901 }); 917 });
902 getDocLink("adblock_plus_{browser}_dnt", url => 918 getDocLink("adblock_plus_{browser}_dnt", url =>
903 { 919 {
904 setLinks("dnt", url); 920 setLinks("dnt", url);
905 }); 921 });
906 922
907 // Advanced tab 923 // Advanced tab
908 let customize = document.querySelectorAll("#customize li[data-pref]"); 924 let customize = document.querySelectorAll("#customize li[data-pref]");
909 customize = Array.prototype.map.call(customize, (checkbox) => 925 customize = Array.prototype.map.call(customize, (checkbox) =>
910 { 926 {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 } 1057 }
1042 1058
1043 function setAcceptableAds() 1059 function setAcceptableAds()
1044 { 1060 {
1045 let acceptableAdsForm = E("acceptable-ads"); 1061 let acceptableAdsForm = E("acceptable-ads");
1046 let acceptableAds = E("acceptable-ads-allow"); 1062 let acceptableAds = E("acceptable-ads-allow");
1047 let acceptableAdsPrivacy = E("acceptable-ads-privacy-allow"); 1063 let acceptableAdsPrivacy = E("acceptable-ads-privacy-allow");
1048 acceptableAdsForm.classList.remove("show-dnt-notification"); 1064 acceptableAdsForm.classList.remove("show-dnt-notification");
1049 acceptableAds.setAttribute("aria-checked", false); 1065 acceptableAds.setAttribute("aria-checked", false);
1050 acceptableAdsPrivacy.setAttribute("aria-checked", false); 1066 acceptableAdsPrivacy.setAttribute("aria-checked", false);
1051 acceptableAdsPrivacy.disabled = true; 1067 acceptableAdsPrivacy.setAttribute("tabindex", 0);
1052 if (acceptableAdsUrl in subscriptionsMap) 1068 if (acceptableAdsUrl in subscriptionsMap)
1053 { 1069 {
1054 acceptableAds.setAttribute("aria-checked", true); 1070 acceptableAds.setAttribute("aria-checked", true);
1055 acceptableAdsPrivacy.disabled = false; 1071 acceptableAdsPrivacy.setAttribute("aria-disabled", false);
1056 } 1072 }
1057 else if (acceptableAdsPrivacyUrl in subscriptionsMap) 1073 else if (acceptableAdsPrivacyUrl in subscriptionsMap)
1058 { 1074 {
1059 acceptableAds.setAttribute("aria-checked", true); 1075 acceptableAds.setAttribute("aria-checked", true);
1060 acceptableAdsPrivacy.setAttribute("aria-checked", true); 1076 acceptableAdsPrivacy.setAttribute("aria-checked", true);
1061 acceptableAdsPrivacy.disabled = false; 1077 acceptableAdsPrivacy.setAttribute("aria-disabled", false);
1062 1078
1063 if (navigator.doNotTrack != 1) 1079 if (navigator.doNotTrack != 1)
1064 acceptableAdsForm.classList.add("show-dnt-notification"); 1080 acceptableAdsForm.classList.add("show-dnt-notification");
1081 }
1082 else
1083 {
1084 // Using aria-disabled in order to keep the focus
1085 acceptableAdsPrivacy.setAttribute("aria-disabled", true);
1086 acceptableAdsPrivacy.setAttribute("tabindex", -1);
1065 } 1087 }
1066 } 1088 }
1067 1089
1068 function isAcceptableAds(url) 1090 function isAcceptableAds(url)
1069 { 1091 {
1070 return url == acceptableAdsUrl || url == acceptableAdsPrivacyUrl; 1092 return url == acceptableAdsUrl || url == acceptableAdsPrivacyUrl;
1071 } 1093 }
1072 1094
1073 function populateLists() 1095 function populateLists()
1074 { 1096 {
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1395 }); 1417 });
1396 browser.runtime.sendMessage({ 1418 browser.runtime.sendMessage({
1397 type: "subscriptions.listen", 1419 type: "subscriptions.listen",
1398 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1420 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1399 "title", "downloadStatus", "downloading"] 1421 "title", "downloadStatus", "downloading"]
1400 }); 1422 });
1401 1423
1402 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1424 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1403 window.addEventListener("hashchange", onHashChange, false); 1425 window.addEventListener("hashchange", onHashChange, false);
1404 } 1426 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld