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

Side by Side Diff: new-options.js

Issue 29340970: Noissue - Several trivial code improvements (adblockplusui) (Closed)
Patch Set: Created April 29, 2016, 12:44 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 | « no previous file | no next file » | 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 var placeholder = table.querySelector(".empty-placeholder"); 45 var placeholder = table.querySelector(".empty-placeholder");
46 if (text && !placeholder) 46 if (text && !placeholder)
47 { 47 {
48 placeholder = document.createElement("li"); 48 placeholder = document.createElement("li");
49 placeholder.className = "empty-placeholder"; 49 placeholder.className = "empty-placeholder";
50 placeholder.textContent = getMessage(text); 50 placeholder.textContent = getMessage(text);
51 table.appendChild(placeholder); 51 table.appendChild(placeholder);
52 } 52 }
53 else if (placeholder) 53 else if (placeholder)
54 table.removeChild(placeholder); 54 table.removeChild(placeholder);
55 } 55 };
56 56
57 Collection.prototype._createElementQuery = function(item) 57 Collection.prototype._createElementQuery = function(item)
58 { 58 {
59 var access = (item.url || item.text).replace(/'/g, "\\'"); 59 var access = (item.url || item.text).replace(/'/g, "\\'");
60 return function(container) 60 return function(container)
61 { 61 {
62 return container.querySelector("[data-access='" + access + "']"); 62 return container.querySelector("[data-access='" + access + "']");
63 }; 63 };
64 }; 64 };
65 65
66 Collection.prototype._getItemTitle = function(item, i) 66 Collection.prototype._getItemTitle = function(item, i)
67 { 67 {
68 if (item.url == acceptableAdsUrl) 68 if (item.url == acceptableAdsUrl)
69 return getMessage("options_acceptableAds_description"); 69 return getMessage("options_acceptableAds_description");
70 if (this.details[i].useOriginalTitle && item.originalTitle) 70 if (this.details[i].useOriginalTitle && item.originalTitle)
71 return item.originalTitle; 71 return item.originalTitle;
72 return item.title || item.url || item.text; 72 return item.title || item.url || item.text;
73 }; 73 };
74 74
75 Collection.prototype.addItems = function() 75 Collection.prototype.addItems = function()
76 { 76 {
77 var length = Array.prototype.push.apply(this.items, arguments); 77 var length = Array.prototype.push.apply(this.items, arguments);
78 if (length == 0) 78 if (length == 0)
79 return; 79 return;
80 80
81 this.items.sort(function(a, b) 81 this.items.sort(function(a, b)
82 { 82 {
83 // Make sure that Acceptable Ads is always last, since it cannot be 83 // Make sure that Acceptable Ads is always last, since it cannot be
84 // disabled, but only be removed. That way it's grouped together with 84 // disabled, but only be removed. That way it's grouped together with
85 // the "Own filter list" which cannot be disabled either at the bottom 85 // the "Own filter list" which cannot be disabled either at the bottom
86 // of the filter lists in the Advanced tab. 86 // of the filter lists in the Advanced tab.
87 if (a.url == acceptableAdsUrl) 87 if (a.url == acceptableAdsUrl)
88 return 1; 88 return 1;
89 if (b.url == acceptableAdsUrl) 89 if (b.url == acceptableAdsUrl)
90 return -1; 90 return -1;
91 91
92 var aTitle = this._getItemTitle(a, 0).toLowerCase(); 92 var aTitle = this._getItemTitle(a, 0).toLowerCase();
93 var bTitle = this._getItemTitle(b, 0).toLowerCase(); 93 var bTitle = this._getItemTitle(b, 0).toLowerCase();
94 return aTitle.localeCompare(bTitle); 94 return aTitle.localeCompare(bTitle);
95 }.bind(this)); 95 }.bind(this));
96 96
97 for (var j = 0; j < this.details.length; j++) 97 for (var j = 0; j < this.details.length; j++)
98 { 98 {
99 var table = E(this.details[j].id); 99 var table = E(this.details[j].id);
100 var template = table.querySelector("template"); 100 var template = table.querySelector("template");
101 for (var i = 0; i < arguments.length; i++) 101 for (var i = 0; i < arguments.length; i++)
102 { 102 {
103 var item = arguments[i]; 103 var item = arguments[i];
104 var listItem = document.createElement("li"); 104 var listItem = document.createElement("li");
105 listItem.appendChild(document.importNode(template.content, true)); 105 listItem.appendChild(document.importNode(template.content, true));
106 listItem.setAttribute("data-access", item.url || item.text); 106 listItem.setAttribute("data-access", item.url || item.text);
107 107
108 var labelId = "label-" + (++maxLabelId); 108 var labelId = "label-" + (++maxLabelId);
109 var label = listItem.querySelector(".display"); 109 var label = listItem.querySelector(".display");
110 label.setAttribute("id", labelId); 110 label.setAttribute("id", labelId);
111 111
112 var control = listItem.querySelector(".control"); 112 var control = listItem.querySelector(".control");
113 if (control) 113 if (control)
114 { 114 {
115 control.setAttribute("aria-labelledby", labelId); 115 control.setAttribute("aria-labelledby", labelId);
116 control.addEventListener("click", this.details[j].onClick, false); 116 control.addEventListener("click", this.details[j].onClick, false);
117 117
118 var role = control.getAttribute("role"); 118 var role = control.getAttribute("role");
119 if (role == "checkbox" && !label.hasAttribute("data-action")) 119 if (role == "checkbox" && !label.hasAttribute("data-action"))
120 { 120 {
121 var controlId = "control-" + maxLabelId; 121 var controlId = "control-" + maxLabelId;
122 control.setAttribute("id", controlId); 122 control.setAttribute("id", controlId);
123 label.setAttribute("for", controlId); 123 label.setAttribute("for", controlId);
124 } 124 }
125 } 125 }
126 126
127 this._setEmpty(table, null); 127 this._setEmpty(table, null);
128 if (table.hasChildNodes()) 128 if (table.hasChildNodes())
129 { 129 {
130 table.insertBefore(listItem, 130 table.insertBefore(listItem,
131 table.childNodes[this.items.indexOf(item)]); 131 table.childNodes[this.items.indexOf(item)]);
132 } 132 }
133 else 133 else
134 table.appendChild(listItem); 134 table.appendChild(listItem);
135 this.updateItem(item); 135 this.updateItem(item);
136 } 136 }
137 } 137 }
138 return length; 138 return length;
139 }; 139 };
140 140
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 }, 851 },
852 function(subscriptions) 852 function(subscriptions)
853 { 853 {
854 // Load filters 854 // Load filters
855 for (var i = 0; i < subscriptions.length; i++) 855 for (var i = 0; i < subscriptions.length; i++)
856 { 856 {
857 ext.backgroundPage.sendMessage( 857 ext.backgroundPage.sendMessage(
858 { 858 {
859 type: "filters.get", 859 type: "filters.get",
860 subscriptionUrl: subscriptions[i].url 860 subscriptionUrl: subscriptions[i].url
861 }, 861 },
862 function(filters) 862 function(filters)
863 { 863 {
864 for (var i = 0; i < filters.length; i++) 864 for (var i = 0; i < filters.length; i++)
865 updateFilter(filters[i]); 865 updateFilter(filters[i]);
866 }); 866 });
867 } 867 }
868 }); 868 });
869 loadRecommendations(); 869 loadRecommendations();
870 ext.backgroundPage.sendMessage( 870 ext.backgroundPage.sendMessage(
871 { 871 {
872 type: "prefs.get", 872 type: "prefs.get",
873 key: "subscriptions_exceptionsurl" 873 key: "subscriptions_exceptionsurl"
874 }, 874 },
875 function(url) 875 function(url)
876 { 876 {
877 acceptableAdsUrl = url; 877 acceptableAdsUrl = url;
878 updateSubscription({ 878 updateSubscription({
879 url: acceptableAdsUrl, 879 url: acceptableAdsUrl,
880 disabled: true 880 disabled: true
881 }); 881 });
882 882
883 // Load user subscriptions 883 // Load user subscriptions
884 ext.backgroundPage.sendMessage( 884 ext.backgroundPage.sendMessage(
885 { 885 {
886 type: "subscriptions.get", 886 type: "subscriptions.get",
887 downloadable: true 887 downloadable: true
888 }, 888 },
889 function(subscriptions) 889 function(subscriptions)
890 { 890 {
891 for (var i = 0; i < subscriptions.length; i++) 891 for (var i = 0; i < subscriptions.length; i++)
892 onSubscriptionMessage("added", subscriptions[i]); 892 onSubscriptionMessage("added", subscriptions[i]);
893 }); 893 });
894 }); 894 });
895 } 895 }
896 896
897 function addWhitelistedDomain() 897 function addWhitelistedDomain()
898 { 898 {
(...skipping 18 matching lines...) Expand all
917 for (var i = 0; i < customFilterItems.length; i++) 917 for (var i = 0; i < customFilterItems.length; i++)
918 filterTexts.push(customFilterItems[i].text); 918 filterTexts.push(customFilterItems[i].text);
919 E("custom-filters-raw").value = filterTexts.join("\n"); 919 E("custom-filters-raw").value = filterTexts.join("\n");
920 } 920 }
921 921
922 function addEnableSubscription(url, title, homepage) 922 function addEnableSubscription(url, title, homepage)
923 { 923 {
924 var messageType = null; 924 var messageType = null;
925 var knownSubscription = subscriptionsMap[url]; 925 var knownSubscription = subscriptionsMap[url];
926 if (knownSubscription && knownSubscription.disabled == true) 926 if (knownSubscription && knownSubscription.disabled == true)
927 messageType = "subscriptions.toggle" 927 messageType = "subscriptions.toggle";
928 else 928 else
929 messageType = "subscriptions.add" 929 messageType = "subscriptions.add";
930 930
931 var message = { 931 var message = {
932 type: messageType, 932 type: messageType,
933 url: url 933 url: url
934 }; 934 };
935 if (title) 935 if (title)
936 message.title = title; 936 message.title = title;
937 if (homepage) 937 if (homepage)
938 message.homepage = homepage; 938 message.homepage = homepage;
939 939
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 1063
1064 var checkbox = document.querySelector("[data-pref='" + key + "'] button[role ='checkbox']"); 1064 var checkbox = document.querySelector("[data-pref='" + key + "'] button[role ='checkbox']");
1065 if (checkbox) 1065 if (checkbox)
1066 checkbox.setAttribute("aria-checked", value); 1066 checkbox.setAttribute("aria-checked", value);
1067 } 1067 }
1068 1068
1069 function onShareLinkClick(e) 1069 function onShareLinkClick(e)
1070 { 1070 {
1071 e.preventDefault(); 1071 e.preventDefault();
1072 1072
1073 getDocLink("share-general", function(link) 1073 getDocLink("share-general", openSharePopup);
1074 {
1075 openSharePopup(link);
1076 });
1077 } 1074 }
1078 1075
1079 function updateShareLink() 1076 function updateShareLink()
1080 { 1077 {
1081 var shareResources = [ 1078 var shareResources = [
1082 "https://facebook.com/plugins/like.php?", 1079 "https://facebook.com/plugins/like.php?",
1083 "https://platform.twitter.com/widgets/", 1080 "https://platform.twitter.com/widgets/",
1084 "https://apis.google.com/se/0/_/+1/fastbutton?" 1081 "https://apis.google.com/se/0/_/+1/fastbutton?"
1085 ]; 1082 ];
1086 var isAnyBlocked = false; 1083 var isAnyBlocked = false;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 }); 1154 });
1158 ext.backgroundPage.sendMessage( 1155 ext.backgroundPage.sendMessage(
1159 { 1156 {
1160 type: "subscriptions.listen", 1157 type: "subscriptions.listen",
1161 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1158 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1162 "title", "downloadStatus", "downloading"] 1159 "title", "downloadStatus", "downloading"]
1163 }); 1160 });
1164 1161
1165 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1162 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1166 })(); 1163 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld