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

Side by Side Diff: chrome/content/ui/firstRun.js

Issue 5056848617013248: Issue 1706 - Move first-run page to adblockplusui repository (Closed)
Patch Set: Export variables differently in common.js Created Jan. 7, 2015, 6:58 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 | « chrome/content/ui/firstRun.html ('k') | chrome/content/ui/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
(Empty)
1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
18 "use strict";
19
20 (function()
21 {
22 // Load subscriptions for features
23 var featureSubscriptions = [
24 {
25 feature: "malware",
26 homepage: "http://malwaredomains.com/",
27 title: "Malware Domains",
28 url: "https://easylist-downloads.adblockplus.org/malwaredomains_full.txt"
29 },
30 {
31 feature: "social",
32 homepage: "https://www.fanboy.co.nz/",
33 title: "Fanboy's Social Blocking List",
34 url: "https://easylist-downloads.adblockplus.org/fanboy-social.txt"
35 },
36 {
37 feature: "tracking",
38 homepage: "https://easylist.adblockplus.org/",
39 title: "EasyPrivacy",
40 url: "https://easylist-downloads.adblockplus.org/easyprivacy.txt"
41 }
42 ];
43
44 function onDOMLoaded()
45 {
46 // Set up URLs
47 var donateLink = E("donate");
48 donateLink.href = Utils.getDocLink("donate");
49
50 var contributors = E("contributors");
51 contributors.href = Utils.getDocLink("contributors");
52
53 setLinks("acceptableAdsExplanation", Utils.getDocLink("acceptable_ads_criter ia"), openFilters);
54 setLinks("share-headline", Utils.getDocLink("contribute"));
55
56 if (typeof backgroundPage != "undefined")
57 {
58 // Show warning if data corruption was detected
59 if (backgroundPage.seenDataCorruption)
60 {
61 E("dataCorruptionWarning").removeAttribute("hidden");
62 setLinks("dataCorruptionWarning", Utils.getDocLink("knownIssuesChrome_fi lterstorage"));
63 }
64
65 // Show warning if filterlists settings were reinitialized
66 if (backgroundPage.filterlistsReinitialized)
67 {
68 E("filterlistsReinitializedWarning").removeAttribute("hidden");
69 setLinks("filterlistsReinitializedWarning", openFilters);
70 }
71 }
72
73 // Show warning if Safari version isn't supported
74 var info = require("info");
75 if (info.platform == "safari" && (
76 Services.vc.compare(info.platformVersion, "6.0") < 0 || // beforeload br eaks websites in Safari 5
77 Services.vc.compare(info.platformVersion, "6.1") == 0 || // extensions ar e broken in 6.1 and 7.0
78 Services.vc.compare(info.platformVersion, "7.0") == 0
79 ))
80 E("legacySafariWarning").removeAttribute("hidden");
81
82 // Set up feature buttons linked to subscriptions
83 featureSubscriptions.forEach(setToggleSubscriptionButton);
84 var filterListener = function(action)
85 {
86 if (/^subscription\.(added|removed|disabled)$/.test(action))
87 {
88 for (var i = 0; i < featureSubscriptions.length; i++)
89 {
90 var featureSubscription = featureSubscriptions[i];
91 updateToggleButton(featureSubscription.feature, isSubscriptionEnabled( featureSubscription));
92 }
93 }
94 }
95 FilterNotifier.addListener(filterListener);
96 window.addEventListener("unload", function(event)
97 {
98 FilterNotifier.removeListener(filterListener);
99 }, false);
100
101 initSocialLinks();
102 }
103
104 function isSubscriptionEnabled(featureSubscription)
105 {
106 return featureSubscription.url in FilterStorage.knownSubscriptions
107 && !Subscription.fromURL(featureSubscription.url).disabled;
108 }
109
110 function setToggleSubscriptionButton(featureSubscription)
111 {
112 var feature = featureSubscription.feature;
113
114 var element = E("toggle-" + feature);
115 updateToggleButton(feature, isSubscriptionEnabled(featureSubscription));
116 element.addEventListener("click", function(event)
117 {
118 var subscription = Subscription.fromURL(featureSubscription.url);
119 if (isSubscriptionEnabled(featureSubscription))
120 FilterStorage.removeSubscription(subscription);
121 else
122 {
123 subscription.disabled = false;
124 subscription.title = featureSubscription.title;
125 subscription.homepage = featureSubscription.homepage;
126 FilterStorage.addSubscription(subscription);
127 if (!subscription.lastDownload)
128 Synchronizer.execute(subscription);
129 }
130 }, false);
131 }
132
133 function openSharePopup(url)
134 {
135 var iframe = E("share-popup");
136 var glassPane = E("glass-pane");
137 var popupMessageReceived = false;
138
139 var popupMessageListener = function(event)
140 {
141 var originFilter = Filter.fromText("||adblockplus.org^");
142 if (!originFilter.matches(event.origin, "OTHER", null, null))
143 return;
144
145 var width = event.data.width;
146 var height = event.data.height;
147 iframe.width = width;
148 iframe.height = height;
149 iframe.style.marginTop = -height/2 + "px";
150 iframe.style.marginLeft = -width/2 + "px";
151 popupMessageReceived = true;
152 window.removeEventListener("message", popupMessageListener);
153 };
154 // Firefox requires last parameter to be true to be triggered by unprivilege d pages
155 window.addEventListener("message", popupMessageListener, false, true);
156
157 var popupLoadListener = function()
158 {
159 if (popupMessageReceived)
160 {
161 iframe.className = "visible";
162
163 var popupCloseListener = function()
164 {
165 iframe.className = glassPane.className = "";
166 document.removeEventListener("click", popupCloseListener);
167 };
168 document.addEventListener("click", popupCloseListener, false);
169 }
170 else
171 {
172 glassPane.className = "";
173 window.removeEventListener("message", popupMessageListener);
174 }
175
176 iframe.removeEventListener("load", popupLoadListener);
177 };
178 iframe.addEventListener("load", popupLoadListener, false);
179
180 iframe.src = url;
181 glassPane.className = "visible";
182 }
183
184 function initSocialLinks()
185 {
186 var networks = ["twitter", "facebook", "gplus"];
187 networks.forEach(function(network)
188 {
189 var link = E("share-" + network);
190 link.addEventListener("click", onSocialLinkClick, false);
191 });
192 }
193
194 function onSocialLinkClick(event)
195 {
196 // Don't open the share page if the sharing script would be blocked
197 var filter = defaultMatcher.matchesAny(event.target.getAttribute("data-scrip t"), "SCRIPT", "adblockplus.org", true);
198 if (!(filter instanceof BlockingFilter))
199 {
200 event.preventDefault();
201 openSharePopup(Utils.getDocLink(event.target.id));
202 }
203 }
204
205 function setLinks(id)
206 {
207 var element = E(id);
208 if (!element)
209 {
210 return;
211 }
212
213 var links = element.getElementsByTagName("a");
214
215 for (var i = 0; i < links.length; i++)
216 {
217 if (typeof arguments[i + 1] == "string")
218 {
219 links[i].href = arguments[i + 1];
220 links[i].setAttribute("target", "_blank");
221 }
222 else if (typeof arguments[i + 1] == "function")
223 {
224 links[i].href = "javascript:void(0);";
225 links[i].addEventListener("click", arguments[i + 1], false);
226 }
227 }
228 }
229
230 function openFilters()
231 {
232 if (typeof UI != "undefined")
233 UI.openFiltersDialog();
234 else
235 {
236 backgroundPage.openOptions();
237 }
238 }
239
240 function updateToggleButton(feature, isEnabled)
241 {
242 var button = E("toggle-" + feature);
243 if (isEnabled)
244 button.classList.remove("off");
245 else
246 button.classList.add("off");
247 }
248
249 document.addEventListener("DOMContentLoaded", onDOMLoaded, false);
250 })();
OLDNEW
« no previous file with comments | « chrome/content/ui/firstRun.html ('k') | chrome/content/ui/i18n.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld