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 March 16, 2016, 11:13 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
« no previous file with comments | « options.html ('k') | skin/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-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 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 }, 595 },
596 function() 596 function()
597 { 597 {
598 E("custom-filters").classList.remove("mode-edit"); 598 E("custom-filters").classList.remove("mode-edit");
599 }); 599 });
600 break; 600 break;
601 case "switch-tab": 601 case "switch-tab":
602 document.body.setAttribute("data-tab", 602 document.body.setAttribute("data-tab",
603 element.getAttribute("data-tab")); 603 element.getAttribute("data-tab"));
604 break; 604 break;
605 case "toggle-pref":
606 ext.backgroundPage.sendMessage(
607 {
608 type: "prefs.toggle",
609 key: findParentData(element, "pref", false)
610 });
611 break;
605 case "update-all-subscriptions": 612 case "update-all-subscriptions":
606 ext.backgroundPage.sendMessage( 613 ext.backgroundPage.sendMessage(
607 { 614 {
608 type: "subscriptions.update" 615 type: "subscriptions.update"
609 }); 616 });
610 break; 617 break;
611 case "open-context-menu": 618 case "open-context-menu":
612 var listItem = findParentData(element, "access", true); 619 var listItem = findParentData(element, "access", true);
613 if (listItem != context) 620 if (listItem != context)
614 listItem.classList.add("show-context-menu"); 621 listItem.classList.add("show-context-menu");
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 var placeholderValue = getMessage("options_dialog_language_find"); 690 var placeholderValue = getMessage("options_dialog_language_find");
684 E("find-language").setAttribute("placeholder", placeholderValue); 691 E("find-language").setAttribute("placeholder", placeholderValue);
685 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); 692 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false);
686 E("whitelisting-textbox").addEventListener("keypress", function(e) 693 E("whitelisting-textbox").addEventListener("keypress", function(e)
687 { 694 {
688 if (getKey(e) == "Enter") 695 if (getKey(e) == "Enter")
689 addWhitelistedDomain(); 696 addWhitelistedDomain();
690 }, false); 697 }, false);
691 698
692 // Advanced tab 699 // Advanced tab
700 var tweaks = document.querySelectorAll("#tweaks li[data-pref]");
701 tweaks = Array.prototype.map.call(tweaks, function(checkbox)
702 {
703 return checkbox.getAttribute("data-pref");
704 });
705 tweaks.forEach(function(key)
706 {
707 getPref(key, function(value)
708 {
709 onPrefMessage(key, value);
710 });
711 });
712 ext.backgroundPage.sendMessage(
713 {
714 type: "app.get",
715 what: "features"
716 },
717 function(features)
718 {
719 hidePref("show_devtools_panel", !features.devToolsPanel);
720 hidePref("safari_contentblocker", !features.safariContentBlocker);
721 });
722
693 var filterTextbox = document.querySelector("#custom-filters-add input"); 723 var filterTextbox = document.querySelector("#custom-filters-add input");
694 placeholderValue = getMessage("options_customFilters_textbox_placeholder"); 724 placeholderValue = getMessage("options_customFilters_textbox_placeholder");
695 filterTextbox.setAttribute("placeholder", placeholderValue); 725 filterTextbox.setAttribute("placeholder", placeholderValue);
696 function addCustomFilters() 726 function addCustomFilters()
697 { 727 {
698 var filterText = filterTextbox.value; 728 var filterText = filterTextbox.value;
699 sendMessageHandleErrors( 729 sendMessageHandleErrors(
700 { 730 {
701 type: "filters.add", 731 type: "filters.add",
702 text: filterText 732 text: filterText
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 { 869 {
840 var customFilterItems = collections.customFilters.items; 870 var customFilterItems = collections.customFilters.items;
841 var filterTexts = []; 871 var filterTexts = [];
842 for (var i = 0; i < customFilterItems.length; i++) 872 for (var i = 0; i < customFilterItems.length; i++)
843 filterTexts.push(customFilterItems[i].text); 873 filterTexts.push(customFilterItems[i].text);
844 E("custom-filters-raw").value = filterTexts.join("\n"); 874 E("custom-filters-raw").value = filterTexts.join("\n");
845 } 875 }
846 876
847 function getAcceptableAdsURL(callback) 877 function getAcceptableAdsURL(callback)
848 { 878 {
849 ext.backgroundPage.sendMessage( 879 getPref("subscriptions_exceptionsurl", function(value)
850 {
851 type: "prefs.get",
852 key: "subscriptions_exceptionsurl"
853 },
854 function(value)
855 { 880 {
856 getAcceptableAdsURL = function(callback) 881 getAcceptableAdsURL = function(callback)
857 { 882 {
858 callback(value); 883 callback(value);
859 } 884 };
860 getAcceptableAdsURL(callback); 885 getAcceptableAdsURL(callback);
861 }); 886 });
862 } 887 }
863 888
864 function addEnableSubscription(url, title, homepage) 889 function addEnableSubscription(url, title, homepage)
865 { 890 {
866 var messageType = null; 891 var messageType = null;
867 var knownSubscription = subscriptionsMap[url]; 892 var knownSubscription = subscriptionsMap[url];
868 if (knownSubscription && knownSubscription.disabled == true) 893 if (knownSubscription && knownSubscription.disabled == true)
869 messageType = "subscriptions.toggle" 894 messageType = "subscriptions.toggle"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 updateShareLink(); 974 updateShareLink();
950 collections.filterLists.removeItem(knownSubscription); 975 collections.filterLists.removeItem(knownSubscription);
951 }); 976 });
952 break; 977 break;
953 case "title": 978 case "title":
954 // TODO: NYI 979 // TODO: NYI
955 break; 980 break;
956 } 981 }
957 } 982 }
958 983
984 function hidePref(key, value)
985 {
986 var element = document.querySelector("[data-pref='" + key + "']");
987 if (element)
988 element.setAttribute("aria-hidden", value);
989 }
990
991 function getPref(key, callback)
992 {
993 var checkPref = getPref.checks[key] || getPref.checkNone;
994 checkPref(function(isActive)
995 {
996 if (!isActive)
997 {
998 hidePref(key, !isActive);
999 return;
1000 }
1001
1002 ext.backgroundPage.sendMessage(
1003 {
1004 type: "prefs.get",
1005 key: key
1006 }, callback);
1007 });
1008 }
1009
1010 getPref.checkNone = function(callback)
1011 {
1012 callback(true);
1013 };
1014
1015 getPref.checks =
1016 {
1017 notifications_ignoredcategories: function(callback)
1018 {
1019 getPref("notifications_showui", callback);
1020 }
1021 };
1022
1023 function onPrefMessage(key, value)
1024 {
1025 var checkbox = document.querySelector("[data-pref='" + key + "'] button[role ='checkbox']");
1026 if (checkbox)
1027 {
1028 if (key == "notifications_ignoredcategories")
1029 value = (value.indexOf("*") == -1);
1030 checkbox.setAttribute("aria-checked", value);
1031 }
1032 else if (key == "notifications_showui")
1033 hidePref("notifications_ignoredcategories", !value);
1034 }
1035
959 function onShareLinkClick(e) 1036 function onShareLinkClick(e)
960 { 1037 {
961 e.preventDefault(); 1038 e.preventDefault();
962 1039
963 getDocLink("share-general", function(link) 1040 getDocLink("share-general", function(link)
964 { 1041 {
965 openSharePopup(link); 1042 openSharePopup(link);
966 }); 1043 });
967 } 1044 }
968 1045
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 var subscription = message.args[0]; 1084 var subscription = message.args[0];
1008 var dialog = E("dialog-content-predefined"); 1085 var dialog = E("dialog-content-predefined");
1009 dialog.querySelector("h3").textContent = subscription.title || ""; 1086 dialog.querySelector("h3").textContent = subscription.title || "";
1010 dialog.querySelector(".url").textContent = subscription.url; 1087 dialog.querySelector(".url").textContent = subscription.url;
1011 openDialog("predefined"); 1088 openDialog("predefined");
1012 } 1089 }
1013 break; 1090 break;
1014 case "filters.listen": 1091 case "filters.listen":
1015 onFilterMessage(message.action, message.args[0]); 1092 onFilterMessage(message.action, message.args[0]);
1016 break; 1093 break;
1094 case "prefs.listen":
1095 onPrefMessage(message.action, message.args[0]);
1096 break;
1017 case "subscriptions.listen": 1097 case "subscriptions.listen":
1018 onSubscriptionMessage(message.action, message.args[0]); 1098 onSubscriptionMessage(message.action, message.args[0]);
1019 break; 1099 break;
1020 } 1100 }
1021 }); 1101 });
1022 1102
1023 ext.backgroundPage.sendMessage( 1103 ext.backgroundPage.sendMessage(
1024 { 1104 {
1025 type: "app.listen", 1105 type: "app.listen",
1026 filter: ["addSubscription", "error"] 1106 filter: ["addSubscription", "error"]
1027 }); 1107 });
1028 ext.backgroundPage.sendMessage( 1108 ext.backgroundPage.sendMessage(
1029 { 1109 {
1030 type: "filters.listen", 1110 type: "filters.listen",
1031 filter: ["added", "loaded", "removed"] 1111 filter: ["added", "loaded", "removed"]
1032 }); 1112 });
1033 ext.backgroundPage.sendMessage( 1113 ext.backgroundPage.sendMessage(
1034 { 1114 {
1115 type: "prefs.listen",
1116 filter: ["notifications_ignoredcategories", "notifications_showui",
1117 "safari_contentblocker", "show_devtools_panel",
1118 "shouldShowBlockElementMenu"]
1119 });
1120 ext.backgroundPage.sendMessage(
1121 {
1035 type: "subscriptions.listen", 1122 type: "subscriptions.listen",
1036 filter: ["added", "disabled", "homepage", "lastDownload", "removed", "title" ] 1123 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1124 "title"]
1037 }); 1125 });
1038 1126
1039 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1127 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1040 })(); 1128 })();
OLDNEW
« no previous file with comments | « options.html ('k') | skin/options.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld