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. 24, 2012, 2:51 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
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 jQuery.fn.center = function()
7 {
8 return this.css({
9 position: "absolute",
10 top: Math.max(0, (($(window).height() - this.outerHeight()) / 2)
11 + $(window).scrollTop()),
12 left: Math.max(0, (($(window).width() - this.outerWidth()) / 2)
13 + $(window).scrollLeft())
14 });
15 };
16
17 function openSharePopup(url)
18 {
19 var glassPane = $("<div/>").addClass("share-popup-glass-pane");
20
21 var iframe = $("<iframe/>")
22 .addClass("share-popup")
23 .attr({
24 src: url,
25 scrolling: "no"
26 })
27 .on("load", function()
28 {
29 iframe.center().fadeIn(150);
30 $(document).click(function()
31 {
32 iframe.fadeOut(100, iframe.remove);
33 glassPane.fadeOut(200, glassPane.remove);
Wladimir Palant 2012/10/25 07:12:00 I think that using CSS transitions for fade-in/fad
34 });
35 });
Wladimir Palant 2012/10/25 07:12:00 Generally I'm trying to avoid creating non-trivial
36
37 var body = $(document.body);
38 body.append(glassPane);
39 glassPane.fadeIn(200, function()
Felix Dahlke 2012/10/24 14:57:33 I would have loved to use Function.bind here, but
Wladimir Palant 2012/10/25 07:12:00 I agree - bind() is good for the obvious cases, th
40 {
41 body.append(iframe);
42 });
43 }
44
45 function initSocialLinks(variant)
46 {
47 var networks = ["twitter", "facebook"];
48 networks.forEach(function(network)
49 {
50 var links = document.getElementsByClassName("share-" + network);
51 for (var i = 0; i < links.length; i++)
52 $(links[i])
53 .attr("href", "#")
Wladimir Palant 2012/10/25 07:12:00 Why does this attribute need to be defined dynamic
54 .click(function(e)
55 {
56 e.preventDefault();
57 openSharePopup(getDocLink(network) + "&variant=" + variant);
58 });
59 });
60 }
61
6 function init() 62 function init()
7 { 63 {
8 // Choose a share text variant randomly 64 // Choose a share text variant randomly
9 var variant = Math.floor(Math.random() * 2) + 1; 65 var variant = Math.floor(Math.random() * 2) + 1;
10 document.documentElement.setAttribute("share-variant", variant); 66 document.documentElement.setAttribute("share-variant", variant);
11 67
12 // Set up page title 68 // Set up page title
13 var titleId = (backgroundPage.isFirstRun ? "firstRun_title_install" : "firstRu n_title_update"); 69 var titleId = (backgroundPage.isFirstRun ? "firstRun_title_install" : "firstRu n_title_update");
14 var pageTitle = i18n.getMessage(titleId); 70 var pageTitle = i18n.getMessage(titleId);
15 document.title = document.getElementById("title-main").textContent = pageTitle ; 71 document.title = document.getElementById("title-main").textContent = pageTitle ;
16 72
17 // Only show changelog link on the update page 73 // Only show changelog link on the update page
18 if (backgroundPage.isFirstRun) 74 if (backgroundPage.isFirstRun)
19 document.getElementById("title-changelog").style.display = "none"; 75 document.getElementById("title-changelog").style.display = "none";
20 76
21 // Set up URLs 77 // Set up URLs
22 var versionId = chrome.app.getDetails().version.split(".").slice(0, 2).join("" ); 78 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"); 79 setLinks("title-changelog", "https://adblockplus.org/releases/adblock-plus-" + versionId + "-for-google-chrome-released");
24 setLinks("acceptableAdsExplanation", getDocLink("acceptable_ads", "criteria"), 80 setLinks("acceptableAdsExplanation", getDocLink("acceptable_ads", "criteria"),
25 backgroundPage.openOptions); 81 backgroundPage.openOptions);
26 82
27 var facebookLinks = document.getElementsByClassName("share-facebook"); 83 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 84
35 var donateLink = document.getElementById("share-donate"); 85 var donateLink = document.getElementById("share-donate");
36 donateLink.href = getDocLink("donate") + "&variant=" + variant; 86 donateLink.href = getDocLink("donate") + "&variant=" + variant;
37 } 87 }
38 window.addEventListener("load", init, false); 88 window.addEventListener("load", init, false);
39 89
40 function setLinks(id) 90 function setLinks(id)
41 { 91 {
42 var element = document.getElementById(id); 92 var element = document.getElementById(id);
43 if (!element) 93 if (!element)
(...skipping 14 matching lines...) Expand all
58 } 108 }
59 } 109 }
60 } 110 }
61 111
62 function getDocLink(page, anchor) 112 function getDocLink(page, anchor)
63 { 113 {
64 return Prefs.documentation_link 114 return Prefs.documentation_link
65 .replace(/%LINK%/g, page) 115 .replace(/%LINK%/g, page)
66 .replace(/%LANG%/g, Utils.appLocale) + (anchor ? "#" + anchor : "" ); 116 .replace(/%LANG%/g, Utils.appLocale) + (anchor ? "#" + anchor : "" );
67 } 117 }
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