OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 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 "use strict"; | 18 "use strict"; |
19 | 19 |
20 (function() | 20 (function() |
21 { | 21 { |
22 var shade; | |
23 var scrollTimer; | |
24 | |
25 // Load subscriptions for features | 22 // Load subscriptions for features |
26 var featureSubscriptions = [ | 23 var featureSubscriptions = [ |
27 { | 24 { |
28 feature: "malware", | 25 feature: "malware", |
29 homepage: "http://malwaredomains.com/", | 26 homepage: "http://malwaredomains.com/", |
30 title: "Malware Domains", | 27 title: "Malware Domains", |
31 url: "https://easylist-downloads.adblockplus.org/malwaredomains_full.txt" | 28 url: "https://easylist-downloads.adblockplus.org/malwaredomains_full.txt" |
32 }, | 29 }, |
33 { | 30 { |
34 feature: "social", | 31 feature: "social", |
35 homepage: "https://www.fanboy.co.nz/", | 32 homepage: "https://www.fanboy.co.nz/", |
36 title: "Fanboy's Social Blocking List", | 33 title: "Fanboy's Social Blocking List", |
37 url: "https://easylist-downloads.adblockplus.org/fanboy-social.txt" | 34 url: "https://easylist-downloads.adblockplus.org/fanboy-social.txt" |
38 }, | 35 }, |
39 { | 36 { |
40 feature: "tracking", | 37 feature: "tracking", |
41 homepage: "https://easylist.adblockplus.org/", | 38 homepage: "https://easylist.adblockplus.org/", |
42 title: "EasyPrivacy", | 39 title: "EasyPrivacy", |
43 url: "https://easylist-downloads.adblockplus.org/easyprivacy.txt" | 40 url: "https://easylist-downloads.adblockplus.org/easyprivacy.txt" |
44 } | 41 } |
45 ]; | 42 ]; |
46 | 43 |
47 function onDOMLoaded() | 44 function onDOMLoaded() |
48 { | 45 { |
| 46 var locale = require("utils").Utils.appLocale; |
| 47 document.documentElement.setAttribute("lang", locale); |
| 48 |
| 49 // Set up URL |
| 50 var donateLink = E("donate"); |
| 51 donateLink.href = Utils.getDocLink("donate"); |
| 52 |
| 53 var contributors = E("contributors"); |
| 54 contributors.href = Utils.getDocLink("contributors"); |
| 55 |
| 56 setLinks("acceptableAdsExplanation", Utils.getDocLink("acceptable_ads_criter
ia"), openFilters); |
| 57 setLinks("share-headline", Utils.getDocLink("contribute")); |
| 58 |
49 // Show warning if data corruption was detected | 59 // Show warning if data corruption was detected |
50 if (typeof backgroundPage != "undefined" && backgroundPage.seenDataCorruptio
n) | 60 if (typeof backgroundPage != "undefined" && backgroundPage.seenDataCorruptio
n) |
51 { | 61 { |
52 E("dataCorruptionWarning").removeAttribute("hidden"); | 62 E("dataCorruptionWarning").removeAttribute("hidden"); |
53 setLinks("dataCorruptionWarning", Utils.getDocLink("knownIssuesChrome_filt
erstorage")); | 63 setLinks("dataCorruptionWarning", Utils.getDocLink("knownIssuesChrome_filt
erstorage")); |
54 } | 64 } |
55 | 65 |
56 // Set up URL | |
57 setLinks("acceptableAdsExplanation", Utils.getDocLink("acceptable_ads_criter
ia"), openFilters); | |
58 | |
59 shade = E("shade"); | |
60 shade.addEventListener("mouseover", scrollPage, false); | |
61 shade.addEventListener("mouseout", stopScroll, false); | |
62 | |
63 // Set up feature buttons linked to subscriptions | 66 // Set up feature buttons linked to subscriptions |
64 featureSubscriptions.forEach(setToggleSubscriptionButton); | 67 featureSubscriptions.forEach(setToggleSubscriptionButton); |
65 var filterListener = function(action) | 68 var filterListener = function(action) |
66 { | 69 { |
67 if (/^subscription\.(added|removed|disabled)$/.test(action)) | 70 if (/^subscription\.(added|removed|disabled)$/.test(action)) |
68 { | 71 { |
69 for (var i = 0; i < featureSubscriptions.length; i++) | 72 for (var i = 0; i < featureSubscriptions.length; i++) |
70 { | 73 { |
71 var featureSubscription = featureSubscriptions[i]; | 74 var featureSubscription = featureSubscriptions[i]; |
72 updateToggleButton(featureSubscription.feature, isSubscriptionEnabled(
featureSubscription)); | 75 updateToggleButton(featureSubscription.feature, isSubscriptionEnabled(
featureSubscription)); |
73 } | 76 } |
74 } | 77 } |
75 } | 78 } |
76 FilterNotifier.addListener(filterListener); | 79 FilterNotifier.addListener(filterListener); |
77 window.addEventListener("unload", function(event) | 80 window.addEventListener("unload", function(event) |
78 { | 81 { |
79 FilterNotifier.removeListener(filterListener); | 82 FilterNotifier.removeListener(filterListener); |
80 }, false); | 83 }, false); |
81 | 84 |
82 window.addEventListener("resize", onWindowResize, false); | 85 // You can click activate-feature or one of the icons to toggle the features
area |
83 document.addEventListener("scroll", onScroll, false); | 86 E("activate-features").addEventListener("click", showFeature, false); |
84 | 87 E("can-do-more-overview").addEventListener("click", showFeature, false); |
85 onWindowResize(); | |
86 | 88 |
87 initSocialLinks(); | 89 initSocialLinks(); |
88 } | 90 } |
89 | 91 |
90 function onScroll() | 92 function showFeature() |
91 { | 93 { |
92 var currentHeight = document.documentElement.scrollTop + document.body.scrol
lTop + document.documentElement.clientHeight; | 94 var canDoMore = E("can-do-more"); |
93 shade.style.opacity = (document.documentElement.scrollHeight == currentHeigh
t) ? "0.0" : "0.5"; | 95 var canDoMoreOverview = E("can-do-more-overview"); |
94 } | 96 var canDoMoreExpanded = E("can-do-more-expanded"); |
95 | 97 |
96 function onWindowResize() | 98 if (!canDoMore.classList.contains("expanded")) |
97 { | 99 { |
98 onScroll(); | 100 canDoMore.classList.add("expanded"); |
99 } | 101 canDoMoreOverview.classList.add("fade"); |
100 | 102 |
101 function toggleTypoCorrectionEnabled() | 103 setTimeout(function() |
102 { | 104 { |
103 Prefs.correctTypos = !Prefs.correctTypos; | 105 canDoMoreOverview.classList.add("hide"); |
| 106 canDoMoreExpanded.classList.remove("hide"); |
| 107 },500); |
| 108 |
| 109 /* Next timeout has to be done because of an js bug. |
| 110 * If you set "display: block" and "opacity: 1" |
| 111 * at the same time the content would be shown |
| 112 * directly without any transition. |
| 113 * With the following timeout the opacity |
| 114 * transition works correctly |
| 115 */ |
| 116 setTimeout(function() |
| 117 { |
| 118 canDoMoreExpanded.classList.remove("fade"); |
| 119 },520); |
| 120 } |
| 121 else if (canDoMore.classList.contains("expanded")) |
| 122 { |
| 123 canDoMore.classList.remove("expanded"); |
| 124 canDoMoreExpanded.classList.add("fade"); |
| 125 |
| 126 setTimeout(function() |
| 127 { |
| 128 canDoMoreExpanded.classList.add("hide"); |
| 129 canDoMoreOverview.classList.remove("hide"); |
| 130 },500); |
| 131 |
| 132 setTimeout(function() |
| 133 { |
| 134 canDoMoreOverview.classList.remove("fade"); |
| 135 },520); |
| 136 } |
104 } | 137 } |
105 | 138 |
106 function isSubscriptionEnabled(featureSubscription) | 139 function isSubscriptionEnabled(featureSubscription) |
107 { | 140 { |
108 return featureSubscription.url in FilterStorage.knownSubscriptions | 141 return featureSubscription.url in FilterStorage.knownSubscriptions |
109 && !Subscription.fromURL(featureSubscription.url).disabled; | 142 && !Subscription.fromURL(featureSubscription.url).disabled; |
110 } | 143 } |
111 | 144 |
112 function setToggleSubscriptionButton(featureSubscription) | 145 function setToggleSubscriptionButton(featureSubscription) |
113 { | 146 { |
(...skipping 11 matching lines...) Expand all Loading... |
125 subscription.disabled = false; | 158 subscription.disabled = false; |
126 subscription.title = featureSubscription.title; | 159 subscription.title = featureSubscription.title; |
127 subscription.homepage = featureSubscription.homepage; | 160 subscription.homepage = featureSubscription.homepage; |
128 FilterStorage.addSubscription(subscription); | 161 FilterStorage.addSubscription(subscription); |
129 if (!subscription.lastDownload) | 162 if (!subscription.lastDownload) |
130 Synchronizer.execute(subscription); | 163 Synchronizer.execute(subscription); |
131 } | 164 } |
132 }, false); | 165 }, false); |
133 } | 166 } |
134 | 167 |
135 function scrollPage() | |
136 { | |
137 if (scrollTimer) | |
138 stopScroll(); | |
139 | |
140 scrollTimer = setInterval(function() | |
141 { | |
142 window.scrollBy(0, 5); | |
143 }, 20); | |
144 } | |
145 | |
146 function stopScroll() | |
147 { | |
148 clearTimeout(scrollTimer); | |
149 scrollTimer = null; | |
150 } | |
151 | |
152 function openSharePopup(url) | 168 function openSharePopup(url) |
153 { | 169 { |
154 var iframe = E("share-popup"); | 170 var iframe = E("share-popup"); |
155 var glassPane = E("glass-pane"); | 171 var glassPane = E("glass-pane"); |
156 var popupMessageReceived = false; | 172 var popupMessageReceived = false; |
157 | 173 |
158 var popupMessageListener = function(event) | 174 var popupMessageListener = function(event) |
159 { | 175 { |
160 var originFilter = Filter.fromText("||adblockplus.org^"); | 176 var originFilter = Filter.fromText("||adblockplus.org^"); |
161 if (!originFilter.matches(event.origin, "OTHER", null, null)) | 177 if (!originFilter.matches(event.origin, "OTHER", null, null)) |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 { | 234 { |
219 event.preventDefault(); | 235 event.preventDefault(); |
220 openSharePopup(Utils.getDocLink(event.target.id)); | 236 openSharePopup(Utils.getDocLink(event.target.id)); |
221 } | 237 } |
222 } | 238 } |
223 | 239 |
224 function setLinks(id) | 240 function setLinks(id) |
225 { | 241 { |
226 var element = E(id); | 242 var element = E(id); |
227 if (!element) | 243 if (!element) |
| 244 { |
228 return; | 245 return; |
229 | 246 } |
| 247 |
230 var links = element.getElementsByTagName("a"); | 248 var links = element.getElementsByTagName("a"); |
| 249 |
231 for (var i = 0; i < links.length; i++) | 250 for (var i = 0; i < links.length; i++) |
232 { | 251 { |
233 if (typeof arguments[i + 1] == "string") | 252 if (typeof arguments[i + 1] == "string") |
234 { | 253 { |
235 links[i].href = arguments[i + 1]; | 254 links[i].href = arguments[i + 1]; |
236 links[i].setAttribute("target", "_blank"); | 255 links[i].setAttribute("target", "_blank"); |
237 } | 256 } |
238 else if (typeof arguments[i + 1] == "function") | 257 else if (typeof arguments[i + 1] == "function") |
239 { | 258 { |
240 links[i].href = "javascript:void(0);"; | 259 links[i].href = "javascript:void(0);"; |
(...skipping 16 matching lines...) Expand all Loading... |
257 { | 276 { |
258 var button = E("toggle-" + feature); | 277 var button = E("toggle-" + feature); |
259 if (isEnabled) | 278 if (isEnabled) |
260 button.classList.remove("off"); | 279 button.classList.remove("off"); |
261 else | 280 else |
262 button.classList.add("off"); | 281 button.classList.add("off"); |
263 } | 282 } |
264 | 283 |
265 document.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 284 document.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
266 })(); | 285 })(); |
OLD | NEW |