Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* | 1 ../abp/chrome/content/ui/firstRun.js |
Wladimir Palant
2013/05/28 13:45:28
Same here, please add to the [mapping] section.
Thomas Greiner
2013/05/28 17:35:12
Done.
| |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | |
3 * Copyright (C) 2006-2013 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 var backgroundPage = chrome.extension.getBackgroundPage(); | |
19 var require = backgroundPage.require; | |
20 var Prefs = require("prefs").Prefs; | |
21 var Utils = require("utils").Utils; | |
22 var Filter = require("filterClasses").Filter; | |
23 | |
24 function openSharePopup(url) | |
25 { | |
26 var iframe = document.getElementById("share-popup"); | |
27 var glassPane = document.getElementById("glass-pane"); | |
28 var popupMessageReceived = false; | |
29 | |
30 var popupMessageListener = function(event) | |
31 { | |
32 var originFilter = Filter.fromText("||adblockplus.org^"); | |
33 if (!originFilter.matches(event.origin, "OTHER", null, null)) | |
34 return; | |
35 | |
36 iframe.width = event.data.width; | |
37 iframe.height = event.data.height; | |
38 popupMessageReceived = true; | |
39 window.removeEventListener("message", popupMessageListener); | |
40 }; | |
41 window.addEventListener("message", popupMessageListener, false); | |
42 | |
43 var popupLoadListener = function() | |
44 { | |
45 if (popupMessageReceived) | |
46 { | |
47 iframe.className = "visible"; | |
48 | |
49 var popupCloseListener = function() | |
50 { | |
51 iframe.className = glassPane.className = ""; | |
52 document.removeEventListener("click", popupCloseListener); | |
53 }; | |
54 document.addEventListener("click", popupCloseListener, false); | |
55 } | |
56 else | |
57 { | |
58 glassPane.className = ""; | |
59 window.removeEventListener("message", popupMessageListener); | |
60 } | |
61 | |
62 iframe.removeEventListener("load", popupLoadListener); | |
63 }; | |
64 iframe.addEventListener("load", popupLoadListener, false); | |
65 | |
66 iframe.src = url; | |
67 glassPane.className = "visible"; | |
68 } | |
69 | |
70 function initSocialLinks(variant) | |
71 { | |
72 var networks = ["twitter", "facebook"]; | |
73 networks.forEach(function(network) | |
74 { | |
75 var links = document.getElementsByClassName("share-" + network); | |
76 for (var i = 0; i < links.length; i++) | |
77 { | |
78 links[i].addEventListener("click", function(e) | |
79 { | |
80 e.preventDefault(); | |
81 openSharePopup(getDocLink("share-" + network) + "&variant=" + variant); | |
82 }, false); | |
83 } | |
84 }); | |
85 } | |
86 | |
87 function init() | |
88 { | |
89 // Choose a share text variant randomly | |
90 var variant = Math.floor(Math.random() * 2) + 1; | |
91 document.documentElement.setAttribute("share-variant", variant); | |
92 | |
93 // Set up page title | |
94 var titleId = (backgroundPage.isFirstRun ? "firstRun_title_install" : "firstRu n_title_update"); | |
95 var pageTitle = i18n.getMessage(titleId); | |
96 document.title = document.getElementById("title-main").textContent = pageTitle ; | |
97 | |
98 // Only show changelog link on the update page | |
99 if (backgroundPage.isFirstRun) | |
100 document.getElementById("title-changelog").style.display = "none"; | |
101 | |
102 // Show warning if data corruption was detected | |
103 if (backgroundPage.seenDataCorruption) | |
104 document.getElementById("dataCorruptionWarning").removeAttribute("hidden"); | |
105 | |
106 // Set up URLs | |
107 var versionId = chrome.app.getDetails().version.split(".").slice(0, 2).join("" ); | |
108 setLinks("title-changelog", "https://adblockplus.org/releases/adblock-plus-" + versionId + "-for-google-chrome-released"); | |
109 setLinks("acceptableAdsExplanation", getDocLink("acceptable_ads_criteria"), | |
110 backgroundPage.openOptions); | |
111 setLinks("dataCorruptionWarning", getDocLink("knownIssuesChrome_filterstorage" )); | |
112 | |
113 initSocialLinks(variant); | |
114 | |
115 var donateLink = document.getElementById("share-donate"); | |
116 donateLink.href = getDocLink("donate") + "&variant=" + variant; | |
117 } | |
118 window.addEventListener("load", init, false); | |
119 | |
120 function setLinks(id) | |
121 { | |
122 var element = document.getElementById(id); | |
123 if (!element) | |
124 return; | |
125 | |
126 var links = element.getElementsByTagName("a"); | |
127 for (var i = 0; i < links.length; i++) | |
128 { | |
129 if (typeof arguments[i + 1] == "string") | |
130 { | |
131 links[i].href = arguments[i + 1]; | |
132 links[i].setAttribute("target", "_blank"); | |
133 } | |
134 else if (typeof arguments[i + 1] == "function") | |
135 { | |
136 links[i].href = "javascript:void(0);"; | |
137 links[i].addEventListener("click", arguments[i + 1], false); | |
138 } | |
139 } | |
140 } | |
141 | |
142 function getDocLink(page) | |
143 { | |
144 return Prefs.documentation_link | |
145 .replace(/%LINK%/g, page) | |
146 .replace(/%LANG%/g, Utils.appLocale); | |
147 } | |
OLD | NEW |