LEFT | RIGHT |
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 */ | 18 /* globals checkShareResource, getDocLink, openSharePopup, E */ |
19 | 19 |
20 "use strict"; | 20 "use strict"; |
21 | 21 |
| 22 (function() |
22 { | 23 { |
23 function onDOMLoaded() | 24 function onDOMLoaded() |
24 { | 25 { |
25 // Set up logo image | 26 // Set up logo image |
26 let logo = E("logo"); | 27 let logo = E("logo"); |
27 logo.src = "skin/abp-128.png"; | 28 logo.src = "skin/abp-128.png"; |
28 let errorCallback = function() | 29 let errorCallback = function() |
29 { | 30 { |
30 logo.removeEventListener("error", errorCallback, false); | 31 logo.removeEventListener("error", errorCallback, false); |
31 // 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. |
32 logo.src = "icons/detailed/abp-128.png"; | 33 logo.src = "icons/detailed/abp-128.png"; |
33 }; | 34 }; |
34 logo.addEventListener("error", errorCallback, false); | 35 logo.addEventListener("error", errorCallback, false); |
35 | 36 |
36 // Set up URLs | 37 // Set up URLs |
37 getDocLink("donate", link => | 38 getDocLink("donate", (link) => |
38 { | 39 { |
39 E("donate").href = link; | 40 E("donate").href = link; |
40 }); | 41 }); |
41 | 42 |
42 getDocLink("contributors", link => | 43 getDocLink("contributors", (link) => |
43 { | 44 { |
44 E("contributors").href = link; | 45 E("contributors").href = link; |
45 }); | 46 }); |
46 | 47 |
47 getDocLink("acceptable_ads_criteria", link => | 48 getDocLink("acceptable_ads_criteria", (link) => |
48 { | 49 { |
49 setLinks("acceptable-ads-explanation", link, openFilters); | 50 setLinks("acceptable-ads-explanation", link, openFilters); |
50 }); | 51 }); |
51 | 52 |
52 getDocLink("contribute", link => | 53 getDocLink("contribute", (link) => |
53 { | 54 { |
54 setLinks("share-headline", link); | 55 setLinks("share-headline", link); |
55 }); | 56 }); |
56 | 57 |
57 ext.backgroundPage.sendMessage({ | 58 ext.backgroundPage.sendMessage({ |
58 type: "app.get", | 59 type: "app.get", |
59 what: "issues" | 60 what: "issues" |
60 }, issues => | 61 }, (issues) => |
61 { | 62 { |
62 // Show warning if filterlists settings were reinitialized | 63 // Show warning if filterlists settings were reinitialized |
63 if (issues.filterlistsReinitialized) | 64 if (issues.filterlistsReinitialized) |
64 { | 65 { |
65 E("filterlistsReinitializedWarning").removeAttribute("hidden"); | 66 E("filterlistsReinitializedWarning").removeAttribute("hidden"); |
66 setLinks("filterlistsReinitializedWarning", openFilters); | 67 setLinks("filterlistsReinitializedWarning", openFilters); |
67 } | 68 } |
68 }); | 69 }); |
69 | 70 |
70 updateSocialLinks(); | 71 updateSocialLinks(); |
71 | 72 |
72 ext.onMessage.addListener(message => | 73 ext.onMessage.addListener((message) => |
73 { | 74 { |
74 if (message.type == "subscriptions.respond") | 75 if (message.type == "subscriptions.respond") |
| 76 { |
75 updateSocialLinks(); | 77 updateSocialLinks(); |
| 78 } |
76 }); | 79 }); |
77 ext.backgroundPage.sendMessage({ | 80 ext.backgroundPage.sendMessage({ |
78 type: "subscriptions.listen", | 81 type: "subscriptions.listen", |
79 filter: ["added", "removed", "updated", "disabled"] | 82 filter: ["added", "removed", "updated", "disabled"] |
80 }); | 83 }); |
81 } | 84 } |
82 | 85 |
83 function updateSocialLinks() | 86 function updateSocialLinks() |
84 { | 87 { |
85 let networks = ["twitter", "facebook", "gplus"]; | 88 for (let network of ["twitter", "facebook", "gplus"]) |
86 networks.forEach(network => | |
87 { | 89 { |
88 let link = E("share-" + network); | 90 let link = E("share-" + network); |
89 checkShareResource(link.getAttribute("data-script"), isBlocked => | 91 checkShareResource(link.getAttribute("data-script"), (isBlocked) => |
90 { | 92 { |
91 // 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 |
92 if (isBlocked) | 94 if (isBlocked) |
93 link.removeEventListener("click", onSocialLinkClick, false); | 95 link.removeEventListener("click", onSocialLinkClick, false); |
94 else | 96 else |
95 link.addEventListener("click", onSocialLinkClick, false); | 97 link.addEventListener("click", onSocialLinkClick, false); |
96 }); | 98 }); |
97 }); | 99 } |
98 } | 100 } |
99 | 101 |
100 function onSocialLinkClick(event) | 102 function onSocialLinkClick(event) |
101 { | 103 { |
102 if (window.matchMedia("(max-width: 970px)").matches) | 104 if (window.matchMedia("(max-width: 970px)").matches) |
103 return; | 105 return; |
104 | 106 |
105 event.preventDefault(); | 107 event.preventDefault(); |
106 | 108 |
107 getDocLink(event.target.id, link => | 109 getDocLink(event.target.id, (link) => |
108 { | 110 { |
109 openSharePopup(link); | 111 openSharePopup(link); |
110 }); | 112 }); |
111 } | 113 } |
112 | 114 |
113 function setLinks(id, ...args) | 115 function setLinks(id, ...args) |
114 { | 116 { |
115 let element = E(id); | 117 let element = E(id); |
116 if (!element) | 118 if (!element) |
| 119 { |
117 return; | 120 return; |
| 121 } |
118 | 122 |
119 let links = element.getElementsByTagName("a"); | 123 let links = element.getElementsByTagName("a"); |
120 | 124 |
121 for (let i = 0; i < links.length; i++) | 125 for (let i = 0; i < links.length; i++) |
122 { | 126 { |
123 if (typeof args[i] == "string") | 127 if (typeof args[i] == "string") |
124 { | 128 { |
125 links[i].href = args[i]; | 129 links[i].href = args[i]; |
126 links[i].setAttribute("target", "_blank"); | 130 links[i].setAttribute("target", "_blank"); |
127 } | 131 } |
128 else if (typeof args[i] == "function") | 132 else if (typeof args[i] == "function") |
129 { | 133 { |
130 links[i].href = "javascript:void(0);"; | 134 links[i].href = "javascript:void(0);"; |
131 links[i].addEventListener("click", args[i], false); | 135 links[i].addEventListener("click", args[i], false); |
132 } | 136 } |
133 } | 137 } |
134 } | 138 } |
135 | 139 |
136 function openFilters() | 140 function openFilters() |
137 { | 141 { |
138 ext.backgroundPage.sendMessage({type: "app.open", what: "options"}); | 142 ext.backgroundPage.sendMessage({type: "app.open", what: "options"}); |
139 } | 143 } |
140 | 144 |
141 document.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 145 document.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
142 } | 146 }()); |
LEFT | RIGHT |