OLD | NEW |
1 var backgroundPage = chrome.extension.getBackgroundPage(); | 1 var backgroundPage = chrome.extension.getBackgroundPage(); |
2 var require = backgroundPage.require; | 2 var require = backgroundPage.require; |
3 var Prefs = require("prefs").Prefs; | 3 var Prefs = require("prefs").Prefs; |
4 var Utils = require("utils").Utils; | 4 var Utils = require("utils").Utils; |
5 | 5 |
| 6 function openSharePopup(url) |
| 7 { |
| 8 var iframe = document.getElementById("share-popup"); |
| 9 var glassPane = document.getElementById("glass-pane"); |
| 10 |
| 11 var popupMessageListener = function(event) |
| 12 { |
| 13 if (event.origin !== url) |
| 14 return; |
| 15 |
| 16 console.log(event); |
| 17 iframe.width = event.data.width; |
| 18 iframe.height = event.data.height; |
| 19 window.removeEventListener("message", popupMessageListener); |
| 20 }; |
| 21 window.addEventListener("message", popupMessageListener, false); |
| 22 |
| 23 var popupLoadListener = function() |
| 24 { |
| 25 iframe.className = "visible"; |
| 26 |
| 27 var popupCloseListener = function() |
| 28 { |
| 29 iframe.className = glassPane.className = ""; |
| 30 document.removeEventListener("click", popupCloseListener); |
| 31 }; |
| 32 document.addEventListener("click", popupCloseListener, false); |
| 33 iframe.removeEventListener("load", popupLoadListener); |
| 34 }; |
| 35 iframe.addEventListener("load", popupLoadListener, false); |
| 36 |
| 37 iframe.src = url; |
| 38 glassPane.className = "visible"; |
| 39 } |
| 40 |
| 41 function initSocialLinks(variant) |
| 42 { |
| 43 var networks = ["twitter", "facebook"]; |
| 44 networks.forEach(function(network) |
| 45 { |
| 46 var links = document.getElementsByClassName("share-" + network); |
| 47 for (var i = 0; i < links.length; i++) |
| 48 { |
| 49 links[i].addEventListener("click", function(e) |
| 50 { |
| 51 e.preventDefault(); |
| 52 openSharePopup(getDocLink(network) + "&variant=" + variant); |
| 53 }, false); |
| 54 } |
| 55 }); |
| 56 } |
| 57 |
6 function init() | 58 function init() |
7 { | 59 { |
8 // Choose a share text variant randomly | 60 // Choose a share text variant randomly |
9 var variant = Math.floor(Math.random() * 2) + 1; | 61 var variant = Math.floor(Math.random() * 2) + 1; |
10 document.documentElement.setAttribute("share-variant", variant); | 62 document.documentElement.setAttribute("share-variant", variant); |
11 | 63 |
12 // Set up page title | 64 // Set up page title |
13 var titleId = (backgroundPage.isFirstRun ? "firstRun_title_install" : "firstRu
n_title_update"); | 65 var titleId = (backgroundPage.isFirstRun ? "firstRun_title_install" : "firstRu
n_title_update"); |
14 var pageTitle = i18n.getMessage(titleId); | 66 var pageTitle = i18n.getMessage(titleId); |
15 document.title = document.getElementById("title-main").textContent = pageTitle
; | 67 document.title = document.getElementById("title-main").textContent = pageTitle
; |
16 | 68 |
17 // Only show changelog link on the update page | 69 // Only show changelog link on the update page |
18 if (backgroundPage.isFirstRun) | 70 if (backgroundPage.isFirstRun) |
19 document.getElementById("title-changelog").style.display = "none"; | 71 document.getElementById("title-changelog").style.display = "none"; |
20 | 72 |
21 // Set up URLs | 73 // Set up URLs |
22 var versionId = chrome.app.getDetails().version.split(".").slice(0, 2).join(""
); | 74 var versionId = chrome.app.getDetails().version.split(".").slice(0, 2).join(""
); |
23 setLinks("title-changelog", "https://adblockplus.org/releases/adblock-plus-" +
versionId + "-for-google-chrome-released"); | 75 setLinks("title-changelog", "https://adblockplus.org/releases/adblock-plus-" +
versionId + "-for-google-chrome-released"); |
24 setLinks("acceptableAdsExplanation", getDocLink("acceptable_ads", "criteria"), | 76 setLinks("acceptableAdsExplanation", getDocLink("acceptable_ads", "criteria"), |
25 backgroundPage.openOptions); | 77 backgroundPage.openOptions); |
26 | 78 |
27 var facebookLinks = document.getElementsByClassName("share-facebook"); | 79 initSocialLinks(variant); |
28 for (var i = 0; i < facebookLinks.length; i++) | |
29 facebookLinks[i].href = getDocLink("facebook") + "&variant=" + variant; | |
30 | |
31 var twitterLinks = document.getElementsByClassName("share-twitter"); | |
32 for (var i = 0; i < twitterLinks.length; i++) | |
33 twitterLinks[i].href = getDocLink("twitter") + "&variant=" + variant; | |
34 | 80 |
35 var donateLink = document.getElementById("share-donate"); | 81 var donateLink = document.getElementById("share-donate"); |
36 donateLink.href = getDocLink("donate") + "&variant=" + variant; | 82 donateLink.href = getDocLink("donate") + "&variant=" + variant; |
37 } | 83 } |
38 window.addEventListener("load", init, false); | 84 window.addEventListener("load", init, false); |
39 | 85 |
40 function setLinks(id) | 86 function setLinks(id) |
41 { | 87 { |
42 var element = document.getElementById(id); | 88 var element = document.getElementById(id); |
43 if (!element) | 89 if (!element) |
(...skipping 14 matching lines...) Expand all Loading... |
58 } | 104 } |
59 } | 105 } |
60 } | 106 } |
61 | 107 |
62 function getDocLink(page, anchor) | 108 function getDocLink(page, anchor) |
63 { | 109 { |
64 return Prefs.documentation_link | 110 return Prefs.documentation_link |
65 .replace(/%LINK%/g, page) | 111 .replace(/%LINK%/g, page) |
66 .replace(/%LANG%/g, Utils.appLocale) + (anchor ? "#" + anchor : ""
); | 112 .replace(/%LANG%/g, Utils.appLocale) + (anchor ? "#" + anchor : ""
); |
67 } | 113 } |
OLD | NEW |