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

Side by Side Diff: firstRun.js

Issue 8615139: adblockpluschrome: Open share page in lightbox (Closed)
Patch Set: Created Oct. 25, 2012, 11:49 a.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 | « firstRun.html ('k') | skin/firstRun.css » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 popupLoadListener = function()
12 {
13 iframe.className = "visible";
14
15 var popupCloseListener = function()
16 {
17 iframe.className = glassPane.className = "";
18 document.removeEventListener("click", popupCloseListener);
19 };
20 document.addEventListener("click", popupCloseListener, false);
21 iframe.removeEventListener("load", popupLoadListener);
22 };
23
24 iframe.addEventListener("load", popupLoadListener, false);
25 iframe.src = url;
26 glassPane.className = "visible";
27 }
28
29 function initSocialLinks(variant)
30 {
31 var networks = ["twitter", "facebook"];
32 networks.forEach(function(network)
33 {
34 var links = document.getElementsByClassName("share-" + network);
35 for (var i = 0; i < links.length; i++)
36 {
37 links[i].addEventListener("click", function(e)
38 {
39 e.preventDefault();
40 openSharePopup(getDocLink(network) + "&variant=" + variant);
41 }, false);
42 }
43 });
44 }
45
6 function init() 46 function init()
7 { 47 {
8 // Choose a share text variant randomly 48 // Choose a share text variant randomly
9 var variant = Math.floor(Math.random() * 2) + 1; 49 var variant = Math.floor(Math.random() * 2) + 1;
10 document.documentElement.setAttribute("share-variant", variant); 50 document.documentElement.setAttribute("share-variant", variant);
11 51
12 // Set up page title 52 // Set up page title
13 var titleId = (backgroundPage.isFirstRun ? "firstRun_title_install" : "firstRu n_title_update"); 53 var titleId = (backgroundPage.isFirstRun ? "firstRun_title_install" : "firstRu n_title_update");
14 var pageTitle = i18n.getMessage(titleId); 54 var pageTitle = i18n.getMessage(titleId);
15 document.title = document.getElementById("title-main").textContent = pageTitle ; 55 document.title = document.getElementById("title-main").textContent = pageTitle ;
16 56
17 // Only show changelog link on the update page 57 // Only show changelog link on the update page
18 if (backgroundPage.isFirstRun) 58 if (backgroundPage.isFirstRun)
19 document.getElementById("title-changelog").style.display = "none"; 59 document.getElementById("title-changelog").style.display = "none";
20 60
21 // Set up URLs 61 // Set up URLs
22 var versionId = chrome.app.getDetails().version.split(".").slice(0, 2).join("" ); 62 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"); 63 setLinks("title-changelog", "https://adblockplus.org/releases/adblock-plus-" + versionId + "-for-google-chrome-released");
24 setLinks("acceptableAdsExplanation", getDocLink("acceptable_ads", "criteria"), 64 setLinks("acceptableAdsExplanation", getDocLink("acceptable_ads", "criteria"),
25 backgroundPage.openOptions); 65 backgroundPage.openOptions);
26 66
27 var facebookLinks = document.getElementsByClassName("share-facebook"); 67 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 68
35 var donateLink = document.getElementById("share-donate"); 69 var donateLink = document.getElementById("share-donate");
36 donateLink.href = getDocLink("donate") + "&variant=" + variant; 70 donateLink.href = getDocLink("donate") + "&variant=" + variant;
37 } 71 }
38 window.addEventListener("load", init, false); 72 window.addEventListener("load", init, false);
39 73
40 function setLinks(id) 74 function setLinks(id)
41 { 75 {
42 var element = document.getElementById(id); 76 var element = document.getElementById(id);
43 if (!element) 77 if (!element)
(...skipping 14 matching lines...) Expand all
58 } 92 }
59 } 93 }
60 } 94 }
61 95
62 function getDocLink(page, anchor) 96 function getDocLink(page, anchor)
63 { 97 {
64 return Prefs.documentation_link 98 return Prefs.documentation_link
65 .replace(/%LINK%/g, page) 99 .replace(/%LINK%/g, page)
66 .replace(/%LANG%/g, Utils.appLocale) + (anchor ? "#" + anchor : "" ); 100 .replace(/%LANG%/g, Utils.appLocale) + (anchor ? "#" + anchor : "" );
67 } 101 }
OLDNEW
« no previous file with comments | « firstRun.html ('k') | skin/firstRun.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld