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, 9:57 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
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 }
Wladimir Palant 2012/10/25 10:45:03 Missing semicolon?
Felix Dahlke 2012/10/25 12:00:51 Yes, ouch.
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";
Wladimir Palant 2012/10/25 10:45:03 Does it still work if you close the popup and then
Felix Dahlke 2012/10/25 12:00:51 Sure.
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++)
Wladimir Palant 2012/10/25 10:45:03 I consider it acceptable to omit brackets if the f
Felix Dahlke 2012/10/25 12:00:51 OK, seems appropriate.
36 links[i].addEventListener("click", function(e)
37 {
38 e.preventDefault();
39 // openSharePopup(getDocLink(network) + "&variant=" + variant);
40 openSharePopup("http://localhost:8000");
Wladimir Palant 2012/10/25 10:45:03 Debug code apparently.
Felix Dahlke 2012/10/25 12:00:51 Double ouch.
41 }, false);
42 });
43 }
44
6 function init() 45 function init()
7 { 46 {
8 // Choose a share text variant randomly 47 // Choose a share text variant randomly
9 var variant = Math.floor(Math.random() * 2) + 1; 48 var variant = Math.floor(Math.random() * 2) + 1;
10 document.documentElement.setAttribute("share-variant", variant); 49 document.documentElement.setAttribute("share-variant", variant);
11 50
12 // Set up page title 51 // Set up page title
13 var titleId = (backgroundPage.isFirstRun ? "firstRun_title_install" : "firstRu n_title_update"); 52 var titleId = (backgroundPage.isFirstRun ? "firstRun_title_install" : "firstRu n_title_update");
14 var pageTitle = i18n.getMessage(titleId); 53 var pageTitle = i18n.getMessage(titleId);
15 document.title = document.getElementById("title-main").textContent = pageTitle ; 54 document.title = document.getElementById("title-main").textContent = pageTitle ;
16 55
17 // Only show changelog link on the update page 56 // Only show changelog link on the update page
18 if (backgroundPage.isFirstRun) 57 if (backgroundPage.isFirstRun)
19 document.getElementById("title-changelog").style.display = "none"; 58 document.getElementById("title-changelog").style.display = "none";
20 59
21 // Set up URLs 60 // Set up URLs
22 var versionId = chrome.app.getDetails().version.split(".").slice(0, 2).join("" ); 61 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"); 62 setLinks("title-changelog", "https://adblockplus.org/releases/adblock-plus-" + versionId + "-for-google-chrome-released");
24 setLinks("acceptableAdsExplanation", getDocLink("acceptable_ads", "criteria"), 63 setLinks("acceptableAdsExplanation", getDocLink("acceptable_ads", "criteria"),
25 backgroundPage.openOptions); 64 backgroundPage.openOptions);
26 65
27 var facebookLinks = document.getElementsByClassName("share-facebook"); 66 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 67
35 var donateLink = document.getElementById("share-donate"); 68 var donateLink = document.getElementById("share-donate");
36 donateLink.href = getDocLink("donate") + "&variant=" + variant; 69 donateLink.href = getDocLink("donate") + "&variant=" + variant;
37 } 70 }
38 window.addEventListener("load", init, false); 71 window.addEventListener("load", init, false);
39 72
40 function setLinks(id) 73 function setLinks(id)
41 { 74 {
42 var element = document.getElementById(id); 75 var element = document.getElementById(id);
43 if (!element) 76 if (!element)
(...skipping 14 matching lines...) Expand all
58 } 91 }
59 } 92 }
60 } 93 }
61 94
62 function getDocLink(page, anchor) 95 function getDocLink(page, anchor)
63 { 96 {
64 return Prefs.documentation_link 97 return Prefs.documentation_link
65 .replace(/%LINK%/g, page) 98 .replace(/%LINK%/g, page)
66 .replace(/%LANG%/g, Utils.appLocale) + (anchor ? "#" + anchor : "" ); 99 .replace(/%LANG%/g, Utils.appLocale) + (anchor ? "#" + anchor : "" );
67 } 100 }
OLDNEW
« no previous file with comments | « firstRun.html ('k') | skin/firstRun.css » ('j') | skin/firstRun.css » ('J')

Powered by Google App Engine
This is Rietveld