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

Side by Side Diff: firstRun.js

Issue 29375899: Issue 4871 - Start using ESLint for adblockplusui (Closed)
Patch Set: Avoid violating operator-linebreak rule Created March 15, 2017, 4:43 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 | « ext/devtools.js ('k') | i18n.js » ('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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /* globals checkShareResource, getDocLink, openSharePopup, E */
19
18 "use strict"; 20 "use strict";
19 21
20 (function() 22 (function()
21 { 23 {
22 function onDOMLoaded() 24 function onDOMLoaded()
23 { 25 {
24 // Set up logo image 26 // Set up logo image
25 var logo = E("logo"); 27 let logo = E("logo");
26 logo.src = "skin/abp-128.png"; 28 logo.src = "skin/abp-128.png";
27 var errorCallback = function() 29 let errorCallback = function()
28 { 30 {
29 logo.removeEventListener("error", errorCallback, false); 31 logo.removeEventListener("error", errorCallback, false);
30 // We are probably in Chrome/Opera/Safari, the image has a different path. 32 // We are probably in Chrome/Opera/Safari, the image has a different path.
31 logo.src = "icons/detailed/abp-128.png"; 33 logo.src = "icons/detailed/abp-128.png";
32 }; 34 };
33 logo.addEventListener("error", errorCallback, false); 35 logo.addEventListener("error", errorCallback, false);
34 36
35 // Set up URLs 37 // Set up URLs
36 getDocLink("donate", function(link) 38 getDocLink("donate", (link) =>
37 { 39 {
38 E("donate").href = link; 40 E("donate").href = link;
39 }); 41 });
40 42
41 getDocLink("contributors", function(link) 43 getDocLink("contributors", (link) =>
42 { 44 {
43 E("contributors").href = link; 45 E("contributors").href = link;
44 }); 46 });
45 47
46 getDocLink("acceptable_ads_criteria", function(link) 48 getDocLink("acceptable_ads_criteria", (link) =>
47 { 49 {
48 setLinks("acceptable-ads-explanation", link, openFilters); 50 setLinks("acceptable-ads-explanation", link, openFilters);
49 }); 51 });
50 52
51 getDocLink("contribute", function(link) 53 getDocLink("contribute", (link) =>
52 { 54 {
53 setLinks("share-headline", link); 55 setLinks("share-headline", link);
54 }); 56 });
55 57
56 ext.backgroundPage.sendMessage({ 58 ext.backgroundPage.sendMessage({
57 type: "app.get", 59 type: "app.get",
58 what: "issues" 60 what: "issues"
59 }, function(issues) 61 }, (issues) =>
60 { 62 {
61 // Show warning if filterlists settings were reinitialized 63 // Show warning if filterlists settings were reinitialized
62 if (issues.filterlistsReinitialized) 64 if (issues.filterlistsReinitialized)
63 { 65 {
64 E("filterlistsReinitializedWarning").removeAttribute("hidden"); 66 E("filterlistsReinitializedWarning").removeAttribute("hidden");
65 setLinks("filterlistsReinitializedWarning", openFilters); 67 setLinks("filterlistsReinitializedWarning", openFilters);
66 } 68 }
67 }); 69 });
68 70
69 updateSocialLinks(); 71 updateSocialLinks();
70 72
71 ext.onMessage.addListener(function(message) 73 ext.onMessage.addListener((message) =>
72 { 74 {
73 if (message.type == "subscriptions.respond") 75 if (message.type == "subscriptions.respond")
74 { 76 {
75 updateSocialLinks(); 77 updateSocialLinks();
76 } 78 }
77 }); 79 });
78 ext.backgroundPage.sendMessage({ 80 ext.backgroundPage.sendMessage({
79 type: "subscriptions.listen", 81 type: "subscriptions.listen",
80 filter: ["added", "removed", "updated", "disabled"] 82 filter: ["added", "removed", "updated", "disabled"]
81 }); 83 });
82 } 84 }
83 85
84 function updateSocialLinks() 86 function updateSocialLinks()
85 { 87 {
86 var networks = ["twitter", "facebook", "gplus"]; 88 for (let network of ["twitter", "facebook", "gplus"])
87 networks.forEach(function(network)
88 { 89 {
89 var link = E("share-" + network); 90 let link = E("share-" + network);
90 checkShareResource(link.getAttribute("data-script"), function(isBlocked) 91 checkShareResource(link.getAttribute("data-script"), (isBlocked) =>
91 { 92 {
92 // Don't open the share page if the sharing script would be blocked 93 // Don't open the share page if the sharing script would be blocked
93 if (isBlocked) 94 if (isBlocked)
94 link.removeEventListener("click", onSocialLinkClick, false); 95 link.removeEventListener("click", onSocialLinkClick, false);
95 else 96 else
96 link.addEventListener("click", onSocialLinkClick, false); 97 link.addEventListener("click", onSocialLinkClick, false);
97 }); 98 });
98 }); 99 }
99 } 100 }
100 101
101 function onSocialLinkClick(event) 102 function onSocialLinkClick(event)
102 { 103 {
103 if (window.matchMedia("(max-width: 970px)").matches) 104 if (window.matchMedia("(max-width: 970px)").matches)
104 return; 105 return;
105 106
106 event.preventDefault(); 107 event.preventDefault();
107 108
108 getDocLink(event.target.id, function(link) 109 getDocLink(event.target.id, (link) =>
109 { 110 {
110 openSharePopup(link); 111 openSharePopup(link);
111 }); 112 });
112 } 113 }
113 114
114 function setLinks(id) 115 function setLinks(id, ...args)
115 { 116 {
116 var element = E(id); 117 let element = E(id);
117 if (!element) 118 if (!element)
118 { 119 {
119 return; 120 return;
120 } 121 }
121 122
122 var links = element.getElementsByTagName("a"); 123 let links = element.getElementsByTagName("a");
123 124
124 for (var i = 0; i < links.length; i++) 125 for (let i = 0; i < links.length; i++)
125 { 126 {
126 if (typeof arguments[i + 1] == "string") 127 if (typeof args[i] == "string")
127 { 128 {
128 links[i].href = arguments[i + 1]; 129 links[i].href = args[i];
129 links[i].setAttribute("target", "_blank"); 130 links[i].setAttribute("target", "_blank");
130 } 131 }
131 else if (typeof arguments[i + 1] == "function") 132 else if (typeof args[i] == "function")
132 { 133 {
133 links[i].href = "javascript:void(0);"; 134 links[i].href = "javascript:void(0);";
134 links[i].addEventListener("click", arguments[i + 1], false); 135 links[i].addEventListener("click", args[i], false);
135 } 136 }
136 } 137 }
137 } 138 }
138 139
139 function openFilters() 140 function openFilters()
140 { 141 {
141 ext.backgroundPage.sendMessage({type: "app.open", what: "options"}); 142 ext.backgroundPage.sendMessage({type: "app.open", what: "options"});
142 } 143 }
143 144
144 document.addEventListener("DOMContentLoaded", onDOMLoaded, false); 145 document.addEventListener("DOMContentLoaded", onDOMLoaded, false);
145 })(); 146 }());
OLDNEW
« no previous file with comments | « ext/devtools.js ('k') | i18n.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld