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. 25, 2016, 5:50 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.name
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'][name ]");
687 tweaks = Array.prototype.map.call(tweaks, function(checkbox)
688 {
689 return checkbox.name;
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("[name='" + 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)
986 {
987 callback(true);
988 };
989 getPref.checks = {
saroyanm 2016/02/29 14:34:39 Detail: Opening braces should be on it's own row,
Thomas Greiner 2016/02/29 17:32:43 Done. We've never been consistent with that one be
990 notifications_ignoredcategories: function(callback)
991 {
992 getPref("notifications_showui", callback);
993 },
994 safari_contentblocker: function(callback)
995 {
996 ext.backgroundPage.sendMessage(
997 {
998 type: "app.get",
999 what: "features"
1000 },
1001 function(features)
1002 {
1003 callback(features.safariContentBlocker);
1004 });
1005 }
1006 };
1007
1008 function onPrefMessage(key, value)
1009 {
1010 var checkbox = document.querySelector("[name='" + key + "']");
1011 if (checkbox)
1012 {
1013 if (key == "notifications_ignoredcategories")
1014 value = (value.indexOf("*") == -1);
1015 checkbox.setAttribute("aria-checked", value);
1016 }
1017 else if (key == "notifications_showui")
1018 hidePref(key, !value);
1019 }
1020
942 function onShareLinkClick(e) 1021 function onShareLinkClick(e)
943 { 1022 {
944 e.preventDefault(); 1023 e.preventDefault();
945 1024
946 getDocLink("share-general", function(link) 1025 getDocLink("share-general", function(link)
947 { 1026 {
948 openSharePopup(link); 1027 openSharePopup(link);
949 }); 1028 });
950 } 1029 }
951 1030
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 openDialog("predefined"); 1073 openDialog("predefined");
995 } 1074 }
996 else if (message.action == "error") 1075 else if (message.action == "error")
997 { 1076 {
998 alert(message.args.join("\n")); 1077 alert(message.args.join("\n"));
999 } 1078 }
1000 break; 1079 break;
1001 case "filters.listen": 1080 case "filters.listen":
1002 onFilterMessage(message.action, message.args[0]); 1081 onFilterMessage(message.action, message.args[0]);
1003 break; 1082 break;
1083 case "prefs.listen":
1084 onPrefMessage(message.action, message.args[0]);
1085 break;
1004 case "subscriptions.listen": 1086 case "subscriptions.listen":
1005 onSubscriptionMessage(message.action, message.args[0]); 1087 onSubscriptionMessage(message.action, message.args[0]);
1006 break; 1088 break;
1007 } 1089 }
1008 }); 1090 });
1009 1091
1010 ext.backgroundPage.sendMessage( 1092 ext.backgroundPage.sendMessage(
1011 { 1093 {
1012 type: "app.listen", 1094 type: "app.listen",
1013 filter: ["addSubscription", "error"] 1095 filter: ["addSubscription", "error"]
1014 }); 1096 });
1015 ext.backgroundPage.sendMessage( 1097 ext.backgroundPage.sendMessage(
1016 { 1098 {
1017 type: "filters.listen", 1099 type: "filters.listen",
1018 filter: ["added", "loaded", "removed"] 1100 filter: ["added", "loaded", "removed"]
1019 }); 1101 });
1020 ext.backgroundPage.sendMessage( 1102 ext.backgroundPage.sendMessage(
1021 { 1103 {
1104 type: "prefs.listen",
1105 filter: ["notifications_ignoredcategories", "notifications_showui",
1106 "safari_contentblocker", "shouldShowBlockElementMenu"]
1107 });
1108 ext.backgroundPage.sendMessage(
1109 {
1022 type: "subscriptions.listen", 1110 type: "subscriptions.listen",
1023 filter: ["added", "disabled", "homepage", "lastDownload", "removed", "title" ] 1111 filter: ["added", "disabled", "homepage", "lastDownload", "removed", "title" ]
1024 }); 1112 });
1025 1113
1026 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1114 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1027 })(); 1115 })();
OLDNEW

Powered by Google App Engine
This is Rietveld