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

Side by Side Diff: options.js

Issue 29337773: Issue 2377 - Implement user filter lists toggle (Closed)
Patch Set: Created Feb. 26, 2016, 11:27 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« messageResponder.js ('K') | « options.html ('k') | no next file » | 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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 729 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 740
741 function closeDialog() 741 function closeDialog()
742 { 742 {
743 var dialog = E("dialog"); 743 var dialog = E("dialog");
744 dialog.setAttribute("aria-hidden", true); 744 dialog.setAttribute("aria-hidden", true);
745 dialog.removeAttribute("aria-labelledby"); 745 dialog.removeAttribute("aria-labelledby");
746 document.body.removeAttribute("data-dialog"); 746 document.body.removeAttribute("data-dialog");
747 focusedBeforeDialog.focus(); 747 focusedBeforeDialog.focus();
748 } 748 }
749 749
750 function toggleUserLists(e)
751 {
752 e.preventDefault();
753 ext.backgroundPage.sendMessage(
754 {
755 type: "app.userSubscriptionsToggle",
756 state: e.target.getAttribute("aria-checked") == "true"
757 });
758 }
759
750 function populateLists() 760 function populateLists()
751 { 761 {
752 subscriptionsMap = Object.create(null); 762 subscriptionsMap = Object.create(null);
753 filtersMap = Object.create(null); 763 filtersMap = Object.create(null);
754 recommendationsMap = Object.create(null); 764 recommendationsMap = Object.create(null);
755 765
756 // Empty collections and lists 766 // Empty collections and lists
757 for (var property in collections) 767 for (var property in collections)
758 collections[property].clearAll(); 768 collections[property].clearAll();
759 769
770 var userListsControl = document.querySelector("#user-filter-lists .control") ;
771 userListsControl.addEventListener("click", toggleUserLists, false);
760 ext.backgroundPage.sendMessage( 772 ext.backgroundPage.sendMessage(
761 { 773 {
762 type: "subscriptions.get", 774 type: "subscriptions.get",
763 special: true 775 special: true
764 }, 776 },
765 function(subscriptions) 777 function(subscriptions)
766 { 778 {
779 var specialEnabled = false;
767 // Load filters 780 // Load filters
768 for (var i = 0; i < subscriptions.length; i++) 781 for (var i = 0; i < subscriptions.length; i++)
769 { 782 {
783 if (!specialEnabled)
784 specialEnabled = !subscriptions[i].disabled;
770 ext.backgroundPage.sendMessage( 785 ext.backgroundPage.sendMessage(
771 { 786 {
772 type: "filters.get", 787 type: "filters.get",
773 subscriptionUrl: subscriptions[i].url 788 subscriptionUrl: subscriptions[i].url
774 }, 789 },
775 function(filters) 790 function(filters)
776 { 791 {
777 for (var i = 0; i < filters.length; i++) 792 for (var i = 0; i < filters.length; i++)
778 updateFilter(filters[i]); 793 updateFilter(filters[i]);
779 }); 794 });
780 } 795 }
796 userListsControl.setAttribute("aria-checked", specialEnabled);
781 }); 797 });
782 loadRecommendations(); 798 loadRecommendations();
783 getAcceptableAdsURL(function(acceptableAdsUrl) 799 getAcceptableAdsURL(function(acceptableAdsUrl)
784 { 800 {
785 var subscription = Object.create(null); 801 var subscription = Object.create(null);
786 subscription.url = acceptableAdsUrl; 802 subscription.url = acceptableAdsUrl;
787 subscription.disabled = true; 803 subscription.disabled = true;
788 subscription.title = getMessage("options_acceptableAds_description"); 804 subscription.title = getMessage("options_acceptableAds_description");
789 updateSubscription(subscription); 805 updateSubscription(subscription);
790 806
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 url: url 874 url: url
859 }; 875 };
860 if (title) 876 if (title)
861 message.title = title; 877 message.title = title;
862 if (homepage) 878 if (homepage)
863 message.homepage = homepage; 879 message.homepage = homepage;
864 880
865 ext.backgroundPage.sendMessage(message); 881 ext.backgroundPage.sendMessage(message);
866 } 882 }
867 883
884 function onAppMessage(action, args)
885 {
886 switch (action)
887 {
888 case "addSubscription":
889 var subscription = args[0];
890 var dialog = E("dialog-content-predefined");
891 dialog.querySelector("h3").textContent = subscription.title || "";
892 dialog.querySelector(".url").textContent = subscription.url;
893 openDialog("predefined");
894 break;
895 case "error":
896 alert(args.join("\n"));
897 break;
898 case "userSubscriptionsToggle":
899 document.querySelector("#user-filter-lists .control").
900 setAttribute("aria-checked", !args[0]);
901 break;
902 }
903 }
904
868 function onFilterMessage(action, filter) 905 function onFilterMessage(action, filter)
869 { 906 {
870 switch (action) 907 switch (action)
871 { 908 {
872 case "added": 909 case "added":
873 updateFilter(filter); 910 updateFilter(filter);
874 updateShareLink(); 911 updateShareLink();
875 break; 912 break;
876 case "loaded": 913 case "loaded":
877 populateLists(); 914 populateLists();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 1015
979 for (var i = 0; i < shareResources.length; i++) 1016 for (var i = 0; i < shareResources.length; i++)
980 checkShareResource(shareResources[i], onResult); 1017 checkShareResource(shareResources[i], onResult);
981 } 1018 }
982 1019
983 ext.onMessage.addListener(function(message) 1020 ext.onMessage.addListener(function(message)
984 { 1021 {
985 switch (message.type) 1022 switch (message.type)
986 { 1023 {
987 case "app.listen": 1024 case "app.listen":
988 if (message.action == "addSubscription") 1025 onAppMessage(message.action, message.args);
989 {
990 var subscription = message.args[0];
991 var dialog = E("dialog-content-predefined");
992 dialog.querySelector("h3").textContent = subscription.title || "";
993 dialog.querySelector(".url").textContent = subscription.url;
994 openDialog("predefined");
995 }
996 else if (message.action == "error")
997 {
998 alert(message.args.join("\n"));
999 }
1000 break; 1026 break;
1001 case "filters.listen": 1027 case "filters.listen":
1002 onFilterMessage(message.action, message.args[0]); 1028 onFilterMessage(message.action, message.args[0]);
1003 break; 1029 break;
1004 case "subscriptions.listen": 1030 case "subscriptions.listen":
1005 onSubscriptionMessage(message.action, message.args[0]); 1031 onSubscriptionMessage(message.action, message.args[0]);
1006 break; 1032 break;
1007 } 1033 }
1008 }); 1034 });
1009 1035
1010 ext.backgroundPage.sendMessage( 1036 ext.backgroundPage.sendMessage(
1011 { 1037 {
1012 type: "app.listen", 1038 type: "app.listen",
1013 filter: ["addSubscription", "error"] 1039 filter: ["addSubscription", "error", "userSubscriptionsToggle"]
saroyanm 2016/02/26 11:31:22 It's bit inconsistent, but the chrome implementat
Thomas Greiner 2016/03/01 12:11:22 Yes, that feature will be added for Firefox. Howev
1014 }); 1040 });
1015 ext.backgroundPage.sendMessage( 1041 ext.backgroundPage.sendMessage(
1016 { 1042 {
1017 type: "filters.listen", 1043 type: "filters.listen",
1018 filter: ["added", "loaded", "removed"] 1044 filter: ["added", "loaded", "removed"]
1019 }); 1045 });
1020 ext.backgroundPage.sendMessage( 1046 ext.backgroundPage.sendMessage(
1021 { 1047 {
1022 type: "subscriptions.listen", 1048 type: "subscriptions.listen",
1023 filter: ["added", "disabled", "homepage", "lastDownload", "removed", "title" ] 1049 filter: ["added", "disabled", "homepage", "lastDownload", "removed", "title" ]
1024 }); 1050 });
1025 1051
1026 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1052 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1027 })(); 1053 })();
OLDNEW
« messageResponder.js ('K') | « options.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld