Left: | ||
Right: |
OLD | NEW |
---|---|
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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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, setLinks, E */ | 18 /* globals checkShareResource, getDocLink, openSharePopup, setLinks, E */ |
juliandoucette
2017/10/21 16:18:43
@greiner, @saroyanm
"[Deprecation] Synchronous XM
Thomas Greiner
2017/10/23 12:01:55
No, this issue only applies to the development env
| |
19 | 19 |
20 "use strict"; | 20 "use strict"; |
21 | 21 |
22 (function() | 22 (function() |
23 { | 23 { |
24 function onDOMLoaded() | 24 function onDOMLoaded() |
25 { | 25 { |
26 // Set up logo image | 26 function initLanguageSelection() |
27 let logo = E("logo"); | |
28 logo.src = "skin/abp-128.png"; | |
29 let errorCallback = function() | |
30 { | 27 { |
31 logo.removeEventListener("error", errorCallback, false); | 28 const locale = document.getElementById("navbar-locale-selected"); |
32 // We are probably in Chrome/Opera/Safari, the image has a different path. | 29 // skip if page does not have language selection (EG: blog) |
33 logo.src = "icons/detailed/abp-128.png"; | 30 if (!locale) |
34 }; | 31 return; |
35 logo.addEventListener("error", errorCallback, false); | |
36 | 32 |
37 // Set up URLs | 33 locale.onclick = function() |
38 getDocLink("donate", (link) => | 34 { |
35 toggleClass(document.getElementById("navbar-locale-menu"), "visible"); | |
36 }; | |
37 } | |
38 | |
39 function navigationClick(event) | |
39 { | 40 { |
40 E("donate").href = link; | 41 toggleClass(document.getElementById("navbar-menu"), "visible"); |
42 } | |
43 | |
44 function initMenu() | |
45 { | |
46 document.getElementById("navbar-menu-toggle").onclick = navigationClick; | |
47 } | |
48 | |
49 function toggleClass(element, className) | |
Thomas Greiner
2017/10/23 13:17:43
We've already been using `Element.classList` in ot
juliandoucette
2017/10/23 13:27:35
He copied this from abp.org main.js. It's unclear
juliandoucette
2017/10/23 13:29:58
(On that note, we could polyfill classList and ref
Thomas Greiner
2017/10/23 16:45:49
From what I see, if we remove the language selecti
juliandoucette
2017/10/24 14:22:18
See https://codereview.adblockplus.org/29587659
martin
2017/10/26 10:33:16
Done.
| |
50 { | |
51 if (hasClass(element, className)) | |
52 removeClass(element, className); | |
53 else | |
54 addClass(element, className); | |
55 } | |
56 | |
57 function hasClass(element, className) | |
58 { | |
59 return !!element.className.match("\\b" + escapeRegExp(className) + "\\b"); | |
60 } | |
61 | |
62 function addClass(element, className) | |
63 { | |
64 if (hasClass(element, className)) | |
65 return; | |
66 | |
67 if (element.className.length) | |
68 element.className += " "; | |
69 element.className += className; | |
70 } | |
71 | |
72 function removeClass(element, className) | |
73 { | |
74 const regExp = new RegExp("\\s*\\b" + escapeRegExp(className) + "\\b\\s*") ; | |
75 element.className = element.className.replace(regExp, ""); | |
76 } | |
77 | |
78 function escapeRegExp(string) | |
79 { | |
80 return string.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); | |
81 } | |
82 | |
83 initLanguageSelection(); | |
84 initMenu(); | |
85 | |
86 const optionsTrigger = E("options-trigger"); | |
87 | |
88 optionsTrigger.addEventListener("click", (e) => | |
89 { | |
90 e.preventDefault(); | |
91 openFilters(); | |
41 }); | 92 }); |
42 | 93 |
43 getDocLink("contributors", (link) => | 94 setLinks("first-column-description", " https://adblockplus.org/terms"); |
44 { | 95 setLinks("third-column-description", "https://adblockplus.org/acceptable-ads #optout"); |
45 E("contributors").href = link; | 96 setLinks("copyright-notice", "https://eyeo.com"); |
46 }); | |
47 | |
48 getDocLink("acceptable_ads_criteria", (link) => | |
49 { | |
50 setLinks("acceptable-ads-explanation", link, openFilters); | |
51 }); | |
52 | |
53 getDocLink("contribute", (link) => | |
54 { | |
55 setLinks("share-headline", link); | |
56 }); | |
57 | |
58 browser.runtime.sendMessage({ | |
59 type: "app.get", | |
60 what: "issues" | |
61 }, (issues) => | |
62 { | |
63 // Show warning if filterlists settings were reinitialized | |
64 if (issues.filterlistsReinitialized) | |
65 { | |
66 E("filterlistsReinitializedWarning").removeAttribute("hidden"); | |
67 setLinks("filterlistsReinitializedWarning", openFilters); | |
68 } | |
69 }); | |
70 | |
71 updateSocialLinks(); | |
72 | |
73 ext.onMessage.addListener((message) => | |
74 { | |
75 if (message.type == "subscriptions.respond") | |
76 { | |
77 updateSocialLinks(); | |
78 } | |
79 }); | |
80 browser.runtime.sendMessage({ | |
81 type: "subscriptions.listen", | |
82 filter: ["added", "removed", "updated", "disabled"] | |
83 }); | |
84 } | |
85 | |
86 function updateSocialLinks() | |
87 { | |
88 for (let network of ["twitter", "facebook", "gplus"]) | |
89 { | |
90 let link = E("share-" + network); | |
91 checkShareResource(link.getAttribute("data-script"), (isBlocked) => | |
92 { | |
93 // Don't open the share page if the sharing script would be blocked | |
94 if (isBlocked) | |
95 link.removeEventListener("click", onSocialLinkClick, false); | |
96 else | |
97 link.addEventListener("click", onSocialLinkClick, false); | |
98 }); | |
99 } | |
100 } | |
101 | |
102 function onSocialLinkClick(event) | |
103 { | |
104 if (window.matchMedia("(max-width: 970px)").matches) | |
105 return; | |
106 | |
107 event.preventDefault(); | |
108 | |
109 getDocLink(event.target.id, (link) => | |
110 { | |
111 openSharePopup(link); | |
112 }); | |
113 } | 97 } |
114 | 98 |
115 function openFilters() | 99 function openFilters() |
116 { | 100 { |
117 browser.runtime.sendMessage({type: "app.open", what: "options"}); | 101 browser.runtime.sendMessage({type: "app.open", what: "options"}); |
118 } | 102 } |
119 | 103 |
120 document.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 104 document.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
121 }()); | 105 }()); |
OLD | NEW |