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: Rebased to 0e4b41190cf5 Created March 15, 2016, 2:43 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
« 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
693 var filterTextbox = document.querySelector("#custom-filters-add input"); 713 var filterTextbox = document.querySelector("#custom-filters-add input");
694 placeholderValue = getMessage("options_customFilters_textbox_placeholder"); 714 placeholderValue = getMessage("options_customFilters_textbox_placeholder");
695 filterTextbox.setAttribute("placeholder", placeholderValue); 715 filterTextbox.setAttribute("placeholder", placeholderValue);
696 function addCustomFilters() 716 function addCustomFilters()
697 { 717 {
698 var filterText = filterTextbox.value; 718 var filterText = filterTextbox.value;
699 sendMessageHandleErrors( 719 sendMessageHandleErrors(
700 { 720 {
701 type: "filters.add", 721 type: "filters.add",
702 text: filterText 722 text: filterText
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 { 859 {
840 var customFilterItems = collections.customFilters.items; 860 var customFilterItems = collections.customFilters.items;
841 var filterTexts = []; 861 var filterTexts = [];
842 for (var i = 0; i < customFilterItems.length; i++) 862 for (var i = 0; i < customFilterItems.length; i++)
843 filterTexts.push(customFilterItems[i].text); 863 filterTexts.push(customFilterItems[i].text);
844 E("custom-filters-raw").value = filterTexts.join("\n"); 864 E("custom-filters-raw").value = filterTexts.join("\n");
845 } 865 }
846 866
847 function getAcceptableAdsURL(callback) 867 function getAcceptableAdsURL(callback)
848 { 868 {
849 ext.backgroundPage.sendMessage( 869 getPref("subscriptions_exceptionsurl", function(value)
850 {
851 type: "prefs.get",
852 key: "subscriptions_exceptionsurl"
853 },
854 function(value)
855 { 870 {
856 getAcceptableAdsURL = function(callback) 871 getAcceptableAdsURL = function(callback)
857 { 872 {
858 callback(value); 873 callback(value);
859 } 874 };
860 getAcceptableAdsURL(callback); 875 getAcceptableAdsURL(callback);
861 }); 876 });
862 } 877 }
863 878
864 function addEnableSubscription(url, title, homepage) 879 function addEnableSubscription(url, title, homepage)
865 { 880 {
866 var messageType = null; 881 var messageType = null;
867 var knownSubscription = subscriptionsMap[url]; 882 var knownSubscription = subscriptionsMap[url];
868 if (knownSubscription && knownSubscription.disabled == true) 883 if (knownSubscription && knownSubscription.disabled == true)
869 messageType = "subscriptions.toggle" 884 messageType = "subscriptions.toggle"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 updateShareLink(); 964 updateShareLink();
950 collections.filterLists.removeItem(knownSubscription); 965 collections.filterLists.removeItem(knownSubscription);
951 }); 966 });
952 break; 967 break;
953 case "title": 968 case "title":
954 // TODO: NYI 969 // TODO: NYI
955 break; 970 break;
956 } 971 }
957 } 972 }
958 973
974 function hidePref(key, value)
975 {
976 var element = document.querySelector("[data-pref='" + key + "']");
977 if (element)
978 element.setAttribute("aria-hidden", value);
979 }
980
981 function getPref(key, callback)
982 {
983 var checkPref = getPref.checks[key] || getPref.checkNone;
984 checkPref(function(isActive)
985 {
986 if (!isActive)
987 {
988 hidePref(key, !isActive);
989 return;
990 }
991
992 ext.backgroundPage.sendMessage(
993 {
994 type: "prefs.get",
995 key: key
996 }, callback);
997 });
998 }
999
1000 getPref.checkNone = function(callback)
1001 {
1002 callback(true);
1003 };
1004
1005 getPref.checks =
1006 {
1007 notifications_ignoredcategories: function(callback)
1008 {
1009 getPref("notifications_showui", callback);
1010 },
1011 safari_contentblocker: function(callback)
1012 {
1013 ext.backgroundPage.sendMessage(
1014 {
1015 type: "app.get",
1016 what: "features"
1017 },
1018 function(features)
1019 {
1020 callback(features.safariContentBlocker);
1021 });
1022 }
1023 };
1024
1025 function onPrefMessage(key, value)
1026 {
1027 var checkbox = document.querySelector("[data-pref='" + key + "'] button[role ='checkbox']");
1028 if (checkbox)
1029 {
1030 if (key == "notifications_ignoredcategories")
1031 value = (value.indexOf("*") == -1);
1032 checkbox.setAttribute("aria-checked", value);
1033 }
1034 else if (key == "notifications_showui")
1035 hidePref("notifications_ignoredcategories", !value);
1036 }
1037
959 function onShareLinkClick(e) 1038 function onShareLinkClick(e)
960 { 1039 {
961 e.preventDefault(); 1040 e.preventDefault();
962 1041
963 getDocLink("share-general", function(link) 1042 getDocLink("share-general", function(link)
964 { 1043 {
965 openSharePopup(link); 1044 openSharePopup(link);
966 }); 1045 });
967 } 1046 }
968 1047
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 var subscription = message.args[0]; 1086 var subscription = message.args[0];
1008 var dialog = E("dialog-content-predefined"); 1087 var dialog = E("dialog-content-predefined");
1009 dialog.querySelector("h3").textContent = subscription.title || ""; 1088 dialog.querySelector("h3").textContent = subscription.title || "";
1010 dialog.querySelector(".url").textContent = subscription.url; 1089 dialog.querySelector(".url").textContent = subscription.url;
1011 openDialog("predefined"); 1090 openDialog("predefined");
1012 } 1091 }
1013 break; 1092 break;
1014 case "filters.listen": 1093 case "filters.listen":
1015 onFilterMessage(message.action, message.args[0]); 1094 onFilterMessage(message.action, message.args[0]);
1016 break; 1095 break;
1096 case "prefs.listen":
1097 onPrefMessage(message.action, message.args[0]);
1098 break;
1017 case "subscriptions.listen": 1099 case "subscriptions.listen":
1018 onSubscriptionMessage(message.action, message.args[0]); 1100 onSubscriptionMessage(message.action, message.args[0]);
1019 break; 1101 break;
1020 } 1102 }
1021 }); 1103 });
1022 1104
1023 ext.backgroundPage.sendMessage( 1105 ext.backgroundPage.sendMessage(
1024 { 1106 {
1025 type: "app.listen", 1107 type: "app.listen",
1026 filter: ["addSubscription", "error"] 1108 filter: ["addSubscription", "error"]
1027 }); 1109 });
1028 ext.backgroundPage.sendMessage( 1110 ext.backgroundPage.sendMessage(
1029 { 1111 {
1030 type: "filters.listen", 1112 type: "filters.listen",
1031 filter: ["added", "loaded", "removed"] 1113 filter: ["added", "loaded", "removed"]
1032 }); 1114 });
1033 ext.backgroundPage.sendMessage( 1115 ext.backgroundPage.sendMessage(
1034 { 1116 {
1117 type: "prefs.listen",
1118 filter: ["notifications_ignoredcategories", "notifications_showui",
1119 "safari_contentblocker", "shouldShowBlockElementMenu"]
1120 });
1121 ext.backgroundPage.sendMessage(
1122 {
1035 type: "subscriptions.listen", 1123 type: "subscriptions.listen",
1036 filter: ["added", "disabled", "homepage", "lastDownload", "removed", "title" ] 1124 filter: ["added", "disabled", "homepage", "lastDownload", "removed", "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