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

Delta Between Two Patch Sets: options.js

Issue 29337729: Issue 2374 - Implemented Tweaks section in options page (Closed)
Left Patch Set: Created Feb. 25, 2016, 5:50 p.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « options.html ('k') | skin/options.css » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 while (element) 510 while (element)
511 { 511 {
512 if (element.hasAttribute("data-" + dataName)) 512 if (element.hasAttribute("data-" + dataName))
513 return returnElement ? element : element.getAttribute("data-" + dataName ); 513 return returnElement ? element : element.getAttribute("data-" + dataName );
514 514
515 element = element.parentElement; 515 element = element.parentElement;
516 } 516 }
517 return null; 517 return null;
518 } 518 }
519 519
520 function sendMessageHandleErrors(message, onSuccess)
521 {
522 ext.backgroundPage.sendMessage(message, function(errors)
523 {
524 if (errors.length > 0)
525 alert(errors.join("\n"));
526 else if (onSuccess)
527 onSuccess();
528 });
529 }
530
520 function onClick(e) 531 function onClick(e)
521 { 532 {
522 var context = document.querySelector(".show-context-menu"); 533 var context = document.querySelector(".show-context-menu");
523 if (context) 534 if (context)
524 context.classList.remove("show-context-menu"); 535 context.classList.remove("show-context-menu");
525 536
526 var element = e.target; 537 var element = e.target;
527 while (true) 538 while (true)
528 { 539 {
529 if (!element) 540 if (!element)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 break; 581 break;
571 case "import-subscription": 582 case "import-subscription":
572 var url = E("blockingList-textbox").value; 583 var url = E("blockingList-textbox").value;
573 addEnableSubscription(url); 584 addEnableSubscription(url);
574 closeDialog(); 585 closeDialog();
575 break; 586 break;
576 case "open-dialog": 587 case "open-dialog":
577 openDialog(element.getAttribute("data-dialog")); 588 openDialog(element.getAttribute("data-dialog"));
578 break; 589 break;
579 case "save-custom-filters": 590 case "save-custom-filters":
580 ext.backgroundPage.sendMessage( 591 sendMessageHandleErrors(
581 { 592 {
582 type: "filters.importRaw", 593 type: "filters.importRaw",
583 text: E("custom-filters-raw").value 594 text: E("custom-filters-raw").value
595 },
596 function()
597 {
598 E("custom-filters").classList.remove("mode-edit");
584 }); 599 });
585 E("custom-filters").classList.remove("mode-edit");
586 break; 600 break;
587 case "switch-tab": 601 case "switch-tab":
588 document.body.setAttribute("data-tab", 602 document.body.setAttribute("data-tab",
589 element.getAttribute("data-tab")); 603 element.getAttribute("data-tab"));
590 break; 604 break;
591 case "toggle-pref": 605 case "toggle-pref":
592 ext.backgroundPage.sendMessage( 606 ext.backgroundPage.sendMessage(
593 { 607 {
594 type: "prefs.toggle", 608 type: "prefs.toggle",
595 key: element.name 609 key: findParentData(element, "pref", false)
596 }); 610 });
597 break; 611 break;
598 case "update-all-subscriptions": 612 case "update-all-subscriptions":
599 ext.backgroundPage.sendMessage( 613 ext.backgroundPage.sendMessage(
600 { 614 {
601 type: "subscriptions.update" 615 type: "subscriptions.update"
602 }); 616 });
603 break; 617 break;
604 case "open-context-menu": 618 case "open-context-menu":
605 var listItem = findParentData(element, "access", true); 619 var listItem = findParentData(element, "access", true);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 var placeholderValue = getMessage("options_dialog_language_find"); 690 var placeholderValue = getMessage("options_dialog_language_find");
677 E("find-language").setAttribute("placeholder", placeholderValue); 691 E("find-language").setAttribute("placeholder", placeholderValue);
678 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); 692 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false);
679 E("whitelisting-textbox").addEventListener("keypress", function(e) 693 E("whitelisting-textbox").addEventListener("keypress", function(e)
680 { 694 {
681 if (getKey(e) == "Enter") 695 if (getKey(e) == "Enter")
682 addWhitelistedDomain(); 696 addWhitelistedDomain();
683 }, false); 697 }, false);
684 698
685 // Advanced tab 699 // Advanced tab
686 var tweaks = document.querySelectorAll("#tweaks button[role='checkbox'][name ]"); 700 var tweaks = document.querySelectorAll("#tweaks li[data-pref]");
687 tweaks = Array.prototype.map.call(tweaks, function(checkbox) 701 tweaks = Array.prototype.map.call(tweaks, function(checkbox)
688 { 702 {
689 return checkbox.name; 703 return checkbox.getAttribute("data-pref");
690 }); 704 });
691 tweaks.forEach(function(name) 705 tweaks.forEach(function(key)
692 { 706 {
693 getPref(name, function(value) 707 getPref(key, function(value)
694 { 708 {
695 onPrefMessage(name, value); 709 onPrefMessage(key, value);
696 }); 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);
697 }); 721 });
698 722
699 var filterTextbox = document.querySelector("#custom-filters-add input"); 723 var filterTextbox = document.querySelector("#custom-filters-add input");
700 placeholderValue = getMessage("options_customFilters_textbox_placeholder"); 724 placeholderValue = getMessage("options_customFilters_textbox_placeholder");
701 filterTextbox.setAttribute("placeholder", placeholderValue); 725 filterTextbox.setAttribute("placeholder", placeholderValue);
702 function addCustomFilters() 726 function addCustomFilters()
703 { 727 {
704 var filterText = filterTextbox.value; 728 var filterText = filterTextbox.value;
705 ext.backgroundPage.sendMessage( 729 sendMessageHandleErrors(
706 { 730 {
707 type: "filters.add", 731 type: "filters.add",
708 text: filterText 732 text: filterText
733 },
734 function()
735 {
736 filterTextbox.value = "";
709 }); 737 });
710 filterTextbox.value = "";
711 } 738 }
712 E("custom-filters-add").addEventListener("submit", function(e) 739 E("custom-filters-add").addEventListener("submit", function(e)
713 { 740 {
714 e.preventDefault(); 741 e.preventDefault();
715 addCustomFilters(); 742 addCustomFilters();
716 }, false); 743 }, false);
717 var customFilterEditButtons = document.querySelectorAll("#custom-filters-edi t-wrapper button"); 744 var customFilterEditButtons = document.querySelectorAll("#custom-filters-edi t-wrapper button");
718 745
719 E("dialog").addEventListener("keydown", function(e) 746 E("dialog").addEventListener("keydown", function(e)
720 { 747 {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 onSubscriptionMessage("added", subscriptions[i]); 847 onSubscriptionMessage("added", subscriptions[i]);
821 }); 848 });
822 }); 849 });
823 } 850 }
824 851
825 function addWhitelistedDomain() 852 function addWhitelistedDomain()
826 { 853 {
827 var domain = E("whitelisting-textbox"); 854 var domain = E("whitelisting-textbox");
828 if (domain.value) 855 if (domain.value)
829 { 856 {
830 ext.backgroundPage.sendMessage( 857 sendMessageHandleErrors(
831 { 858 {
832 type: "filters.add", 859 type: "filters.add",
833 text: "@@||" + domain.value.toLowerCase() + "^$document" 860 text: "@@||" + domain.value.toLowerCase() + "^$document"
834 }); 861 });
835 } 862 }
836 863
837 domain.value = ""; 864 domain.value = "";
838 document.querySelector("#whitelisting .controls").classList.remove("mode-edi t"); 865 document.querySelector("#whitelisting .controls").classList.remove("mode-edi t");
839 } 866 }
840 867
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 }); 976 });
950 break; 977 break;
951 case "title": 978 case "title":
952 // TODO: NYI 979 // TODO: NYI
953 break; 980 break;
954 } 981 }
955 } 982 }
956 983
957 function hidePref(key, value) 984 function hidePref(key, value)
958 { 985 {
959 var element = document.querySelector("[name='" + key + "']"); 986 var element = document.querySelector("[data-pref='" + key + "']");
960 if (!element) 987 if (element)
961 return; 988 element.setAttribute("aria-hidden", value);
962
963 var parent = findParentData(element, "optional", true);
964 parent.setAttribute("aria-hidden", value);
965 } 989 }
966 990
967 function getPref(key, callback) 991 function getPref(key, callback)
968 { 992 {
969 var checkPref = getPref.checks[key] || getPref.checkNone; 993 var checkPref = getPref.checks[key] || getPref.checkNone;
970 checkPref(function(isActive) 994 checkPref(function(isActive)
971 { 995 {
972 if (!isActive) 996 if (!isActive)
973 { 997 {
974 hidePref(key, !isActive); 998 hidePref(key, !isActive);
975 return; 999 return;
976 } 1000 }
977 1001
978 ext.backgroundPage.sendMessage( 1002 ext.backgroundPage.sendMessage(
979 { 1003 {
980 type: "prefs.get", 1004 type: "prefs.get",
981 key: key 1005 key: key
982 }, callback); 1006 }, callback);
983 }); 1007 });
984 } 1008 }
1009
985 getPref.checkNone = function(callback) 1010 getPref.checkNone = function(callback)
986 { 1011 {
987 callback(true); 1012 callback(true);
988 }; 1013 };
989 getPref.checks = { 1014
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
1015 getPref.checks =
1016 {
990 notifications_ignoredcategories: function(callback) 1017 notifications_ignoredcategories: function(callback)
991 { 1018 {
992 getPref("notifications_showui", callback); 1019 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 } 1020 }
1006 }; 1021 };
1007 1022
1008 function onPrefMessage(key, value) 1023 function onPrefMessage(key, value)
1009 { 1024 {
1010 var checkbox = document.querySelector("[name='" + key + "']"); 1025 var checkbox = document.querySelector("[data-pref='" + key + "'] button[role ='checkbox']");
1011 if (checkbox) 1026 if (checkbox)
1012 { 1027 {
1013 if (key == "notifications_ignoredcategories") 1028 if (key == "notifications_ignoredcategories")
1014 value = (value.indexOf("*") == -1); 1029 value = (value.indexOf("*") == -1);
1015 checkbox.setAttribute("aria-checked", value); 1030 checkbox.setAttribute("aria-checked", value);
1016 } 1031 }
1017 else if (key == "notifications_showui") 1032 else if (key == "notifications_showui")
1018 hidePref(key, !value); 1033 hidePref("notifications_ignoredcategories", !value);
1019 } 1034 }
1020 1035
1021 function onShareLinkClick(e) 1036 function onShareLinkClick(e)
1022 { 1037 {
1023 e.preventDefault(); 1038 e.preventDefault();
1024 1039
1025 getDocLink("share-general", function(link) 1040 getDocLink("share-general", function(link)
1026 { 1041 {
1027 openSharePopup(link); 1042 openSharePopup(link);
1028 }); 1043 });
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 { 1080 {
1066 case "app.listen": 1081 case "app.listen":
1067 if (message.action == "addSubscription") 1082 if (message.action == "addSubscription")
1068 { 1083 {
1069 var subscription = message.args[0]; 1084 var subscription = message.args[0];
1070 var dialog = E("dialog-content-predefined"); 1085 var dialog = E("dialog-content-predefined");
1071 dialog.querySelector("h3").textContent = subscription.title || ""; 1086 dialog.querySelector("h3").textContent = subscription.title || "";
1072 dialog.querySelector(".url").textContent = subscription.url; 1087 dialog.querySelector(".url").textContent = subscription.url;
1073 openDialog("predefined"); 1088 openDialog("predefined");
1074 } 1089 }
1075 else if (message.action == "error")
1076 {
1077 alert(message.args.join("\n"));
1078 }
1079 break; 1090 break;
1080 case "filters.listen": 1091 case "filters.listen":
1081 onFilterMessage(message.action, message.args[0]); 1092 onFilterMessage(message.action, message.args[0]);
1082 break; 1093 break;
1083 case "prefs.listen": 1094 case "prefs.listen":
1084 onPrefMessage(message.action, message.args[0]); 1095 onPrefMessage(message.action, message.args[0]);
1085 break; 1096 break;
1086 case "subscriptions.listen": 1097 case "subscriptions.listen":
1087 onSubscriptionMessage(message.action, message.args[0]); 1098 onSubscriptionMessage(message.action, message.args[0]);
1088 break; 1099 break;
1089 } 1100 }
1090 }); 1101 });
1091 1102
1092 ext.backgroundPage.sendMessage( 1103 ext.backgroundPage.sendMessage(
1093 { 1104 {
1094 type: "app.listen", 1105 type: "app.listen",
1095 filter: ["addSubscription", "error"] 1106 filter: ["addSubscription", "error"]
1096 }); 1107 });
1097 ext.backgroundPage.sendMessage( 1108 ext.backgroundPage.sendMessage(
1098 { 1109 {
1099 type: "filters.listen", 1110 type: "filters.listen",
1100 filter: ["added", "loaded", "removed"] 1111 filter: ["added", "loaded", "removed"]
1101 }); 1112 });
1102 ext.backgroundPage.sendMessage( 1113 ext.backgroundPage.sendMessage(
1103 { 1114 {
1104 type: "prefs.listen", 1115 type: "prefs.listen",
1105 filter: ["notifications_ignoredcategories", "notifications_showui", 1116 filter: ["notifications_ignoredcategories", "notifications_showui",
1106 "safari_contentblocker", "shouldShowBlockElementMenu"] 1117 "safari_contentblocker", "show_devtools_panel",
1118 "shouldShowBlockElementMenu"]
1107 }); 1119 });
1108 ext.backgroundPage.sendMessage( 1120 ext.backgroundPage.sendMessage(
1109 { 1121 {
1110 type: "subscriptions.listen", 1122 type: "subscriptions.listen",
1111 filter: ["added", "disabled", "homepage", "lastDownload", "removed", "title" ] 1123 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1124 "title"]
1112 }); 1125 });
1113 1126
1114 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1127 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1115 })(); 1128 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld