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

Side by Side Diff: options.js

Issue 29337729: Issue 2374 - Implemented Tweaks section in options page (Closed)
Patch Set: Created Feb. 29, 2016, 5:27 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-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 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 { 581 {
582 type: "filters.importRaw", 582 type: "filters.importRaw",
583 text: E("custom-filters-raw").value 583 text: E("custom-filters-raw").value
584 }); 584 });
585 E("custom-filters").classList.remove("mode-edit"); 585 E("custom-filters").classList.remove("mode-edit");
586 break; 586 break;
587 case "switch-tab": 587 case "switch-tab":
588 document.body.setAttribute("data-tab", 588 document.body.setAttribute("data-tab",
589 element.getAttribute("data-tab")); 589 element.getAttribute("data-tab"));
590 break; 590 break;
591 case "toggle-pref":
592 ext.backgroundPage.sendMessage(
593 {
594 type: "prefs.toggle",
595 key: element.getAttribute("data-pref")
596 });
597 break;
591 case "update-all-subscriptions": 598 case "update-all-subscriptions":
592 ext.backgroundPage.sendMessage( 599 ext.backgroundPage.sendMessage(
593 { 600 {
594 type: "subscriptions.update" 601 type: "subscriptions.update"
595 }); 602 });
596 break; 603 break;
597 case "open-context-menu": 604 case "open-context-menu":
598 var listItem = findParentData(element, "access", true); 605 var listItem = findParentData(element, "access", true);
599 if (listItem != context) 606 if (listItem != context)
600 listItem.classList.add("show-context-menu"); 607 listItem.classList.add("show-context-menu");
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 var placeholderValue = getMessage("options_dialog_language_find"); 676 var placeholderValue = getMessage("options_dialog_language_find");
670 E("find-language").setAttribute("placeholder", placeholderValue); 677 E("find-language").setAttribute("placeholder", placeholderValue);
671 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); 678 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false);
672 E("whitelisting-textbox").addEventListener("keypress", function(e) 679 E("whitelisting-textbox").addEventListener("keypress", function(e)
673 { 680 {
674 if (getKey(e) == "Enter") 681 if (getKey(e) == "Enter")
675 addWhitelistedDomain(); 682 addWhitelistedDomain();
676 }, false); 683 }, false);
677 684
678 // Advanced tab 685 // Advanced tab
686 var tweaks = document.querySelectorAll("#tweaks button[role='checkbox'][data -pref]");
687 tweaks = Array.prototype.map.call(tweaks, function(checkbox)
688 {
689 return checkbox.getAttribute("data-pref");
690 });
691 tweaks.forEach(function(name)
692 {
693 getPref(name, function(value)
694 {
695 onPrefMessage(name, value);
696 });
697 });
698
679 var filterTextbox = document.querySelector("#custom-filters-add input"); 699 var filterTextbox = document.querySelector("#custom-filters-add input");
680 placeholderValue = getMessage("options_customFilters_textbox_placeholder"); 700 placeholderValue = getMessage("options_customFilters_textbox_placeholder");
681 filterTextbox.setAttribute("placeholder", placeholderValue); 701 filterTextbox.setAttribute("placeholder", placeholderValue);
682 function addCustomFilters() 702 function addCustomFilters()
683 { 703 {
684 var filterText = filterTextbox.value; 704 var filterText = filterTextbox.value;
685 ext.backgroundPage.sendMessage( 705 ext.backgroundPage.sendMessage(
686 { 706 {
687 type: "filters.add", 707 type: "filters.add",
688 text: filterText 708 text: filterText
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 { 842 {
823 var customFilterItems = collections.customFilters.items; 843 var customFilterItems = collections.customFilters.items;
824 var filterTexts = []; 844 var filterTexts = [];
825 for (var i = 0; i < customFilterItems.length; i++) 845 for (var i = 0; i < customFilterItems.length; i++)
826 filterTexts.push(customFilterItems[i].text); 846 filterTexts.push(customFilterItems[i].text);
827 E("custom-filters-raw").value = filterTexts.join("\n"); 847 E("custom-filters-raw").value = filterTexts.join("\n");
828 } 848 }
829 849
830 function getAcceptableAdsURL(callback) 850 function getAcceptableAdsURL(callback)
831 { 851 {
832 ext.backgroundPage.sendMessage( 852 getPref("subscriptions_exceptionsurl", function(value)
833 {
834 type: "prefs.get",
835 key: "subscriptions_exceptionsurl"
836 },
837 function(value)
838 { 853 {
839 getAcceptableAdsURL = function(callback) 854 getAcceptableAdsURL = function(callback)
840 { 855 {
841 callback(value); 856 callback(value);
842 } 857 };
843 getAcceptableAdsURL(callback); 858 getAcceptableAdsURL(callback);
844 }); 859 });
845 } 860 }
846 861
847 function addEnableSubscription(url, title, homepage) 862 function addEnableSubscription(url, title, homepage)
848 { 863 {
849 var messageType = null; 864 var messageType = null;
850 var knownSubscription = subscriptionsMap[url]; 865 var knownSubscription = subscriptionsMap[url];
851 if (knownSubscription && knownSubscription.disabled == true) 866 if (knownSubscription && knownSubscription.disabled == true)
852 messageType = "subscriptions.toggle" 867 messageType = "subscriptions.toggle"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 updateShareLink(); 947 updateShareLink();
933 collections.filterLists.removeItem(knownSubscription); 948 collections.filterLists.removeItem(knownSubscription);
934 }); 949 });
935 break; 950 break;
936 case "title": 951 case "title":
937 // TODO: NYI 952 // TODO: NYI
938 break; 953 break;
939 } 954 }
940 } 955 }
941 956
957 function hidePref(key, value)
958 {
959 var element = document.querySelector("[data-pref='" + key + "']");
960 if (!element)
961 return;
962
963 var parent = findParentData(element, "optional", true);
964 parent.setAttribute("aria-hidden", value);
965 }
966
967 function getPref(key, callback)
968 {
969 var checkPref = getPref.checks[key] || getPref.checkNone;
970 checkPref(function(isActive)
971 {
972 if (!isActive)
973 {
974 hidePref(key, !isActive);
975 return;
976 }
977
978 ext.backgroundPage.sendMessage(
979 {
980 type: "prefs.get",
981 key: key
982 }, callback);
983 });
984 }
985 getPref.checkNone = function(callback)
saroyanm 2016/03/11 14:55:58 Detail: I assume you grouped the functions for rea
Thomas Greiner 2016/03/15 15:39:26 Done.
986 {
987 callback(true);
988 };
989 getPref.checks =
990 {
991 notifications_ignoredcategories: function(callback)
992 {
993 getPref("notifications_showui", callback);
994 },
995 safari_contentblocker: function(callback)
996 {
997 ext.backgroundPage.sendMessage(
998 {
999 type: "app.get",
1000 what: "features"
1001 },
1002 function(features)
1003 {
1004 callback(features.safariContentBlocker);
1005 });
1006 }
1007 };
1008
1009 function onPrefMessage(key, value)
1010 {
1011 var checkbox = document.querySelector("[data-pref='" + key + "']");
1012 if (checkbox)
1013 {
1014 if (key == "notifications_ignoredcategories")
1015 value = (value.indexOf("*") == -1);
1016 checkbox.setAttribute("aria-checked", value);
1017 }
1018 else if (key == "notifications_showui")
1019 hidePref("notifications_ignoredcategories", !value);
1020 }
1021
942 function onShareLinkClick(e) 1022 function onShareLinkClick(e)
943 { 1023 {
944 e.preventDefault(); 1024 e.preventDefault();
945 1025
946 getDocLink("share-general", function(link) 1026 getDocLink("share-general", function(link)
947 { 1027 {
948 openSharePopup(link); 1028 openSharePopup(link);
949 }); 1029 });
950 } 1030 }
951 1031
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 openDialog("predefined"); 1074 openDialog("predefined");
995 } 1075 }
996 else if (message.action == "error") 1076 else if (message.action == "error")
997 { 1077 {
998 alert(message.args.join("\n")); 1078 alert(message.args.join("\n"));
999 } 1079 }
1000 break; 1080 break;
1001 case "filters.listen": 1081 case "filters.listen":
1002 onFilterMessage(message.action, message.args[0]); 1082 onFilterMessage(message.action, message.args[0]);
1003 break; 1083 break;
1084 case "prefs.listen":
1085 onPrefMessage(message.action, message.args[0]);
1086 break;
1004 case "subscriptions.listen": 1087 case "subscriptions.listen":
1005 onSubscriptionMessage(message.action, message.args[0]); 1088 onSubscriptionMessage(message.action, message.args[0]);
1006 break; 1089 break;
1007 } 1090 }
1008 }); 1091 });
1009 1092
1010 ext.backgroundPage.sendMessage( 1093 ext.backgroundPage.sendMessage(
1011 { 1094 {
1012 type: "app.listen", 1095 type: "app.listen",
1013 filter: ["addSubscription", "error"] 1096 filter: ["addSubscription", "error"]
1014 }); 1097 });
1015 ext.backgroundPage.sendMessage( 1098 ext.backgroundPage.sendMessage(
1016 { 1099 {
1017 type: "filters.listen", 1100 type: "filters.listen",
1018 filter: ["added", "loaded", "removed"] 1101 filter: ["added", "loaded", "removed"]
1019 }); 1102 });
1020 ext.backgroundPage.sendMessage( 1103 ext.backgroundPage.sendMessage(
1021 { 1104 {
1105 type: "prefs.listen",
1106 filter: ["notifications_ignoredcategories", "notifications_showui",
1107 "safari_contentblocker", "shouldShowBlockElementMenu"]
1108 });
1109 ext.backgroundPage.sendMessage(
1110 {
1022 type: "subscriptions.listen", 1111 type: "subscriptions.listen",
1023 filter: ["added", "disabled", "homepage", "lastDownload", "removed", "title" ] 1112 filter: ["added", "disabled", "homepage", "lastDownload", "removed", "title" ]
1024 }); 1113 });
1025 1114
1026 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1115 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1027 })(); 1116 })();
OLDNEW
« messageResponder.js ('K') | « options.html ('k') | skin/options.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld