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

Delta Between Two Patch Sets: firstRun.js

Issue 8615139: adblockpluschrome: Open share page in lightbox (Closed)
Left Patch Set: Created Oct. 23, 2012, 4:12 p.m.
Right Patch Set: Created Oct. 25, 2012, 1:29 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « firstRun.html ('k') | skin/firstRun.css » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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(network) 6 function openSharePopup(url)
7 { 7 {
8 $.fancybox.open([{ 8 var iframe = document.getElementById("share-popup");
9 href: getDocLink(network), 9 var glassPane = document.getElementById("glass-pane");
Wladimir Palant 2012/10/24 09:02:26 We need to pass the variant parameter as well, oth
Felix Dahlke 2012/10/24 14:55:01 Done.
10 type: "iframe", 10
11 width: 546, 11 var popupMessageListener = function(event)
12 height: 546, 12 {
13 padding: 0, 13 if (event.origin !== url)
14 iframe: { 14 return;
15 scrolling: "no" 15
16 } 16 console.log(event);
Wladimir Palant 2012/10/25 13:31:04 Debug code?
17 }]); 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";
18 } 39 }
19 40
20 function initSocialLinks() 41 function initSocialLinks(variant)
21 { 42 {
22 var networks = ["twitter", "facebook"]; 43 var networks = ["twitter", "facebook"];
23 networks.forEach(function(network) 44 networks.forEach(function(network)
24 { 45 {
25 var links = document.getElementsByClassName("share-" + network); 46 var links = document.getElementsByClassName("share-" + network);
26 for (var i = 0; i < links.length; i++) 47 for (var i = 0; i < links.length; i++)
27 links[i].onclick = openSharePopup.bind(undefined, network); 48 {
Wladimir Palant 2012/10/24 09:02:26 Did I mention already that I don't like onfoo? ;)
Felix Dahlke 2012/10/24 14:55:01 You're right, my bad.
49 links[i].addEventListener("click", function(e)
50 {
51 e.preventDefault();
52 openSharePopup(getDocLink("share-" + network) + "&variant=" + variant);
53 }, false);
54 }
28 }); 55 });
29 } 56 }
30 57
31 function init() 58 function init()
32 { 59 {
33 // Choose a share text variant randomly 60 // Choose a share text variant randomly
34 var variant = Math.floor(Math.random() * 2) + 1; 61 var variant = Math.floor(Math.random() * 2) + 1;
35 document.documentElement.setAttribute("share-variant", variant); 62 document.documentElement.setAttribute("share-variant", variant);
36 63
37 // Set up page title 64 // Set up page title
38 var titleId = (backgroundPage.isFirstRun ? "firstRun_title_install" : "firstRu n_title_update"); 65 var titleId = (backgroundPage.isFirstRun ? "firstRun_title_install" : "firstRu n_title_update");
39 var pageTitle = i18n.getMessage(titleId); 66 var pageTitle = i18n.getMessage(titleId);
40 document.title = document.getElementById("title-main").textContent = pageTitle ; 67 document.title = document.getElementById("title-main").textContent = pageTitle ;
41 68
42 // Only show changelog link on the update page 69 // Only show changelog link on the update page
43 if (backgroundPage.isFirstRun) 70 if (backgroundPage.isFirstRun)
44 document.getElementById("title-changelog").style.display = "none"; 71 document.getElementById("title-changelog").style.display = "none";
45 72
46 // Set up URLs 73 // Set up URLs
47 var versionId = chrome.app.getDetails().version.split(".").slice(0, 2).join("" ); 74 var versionId = chrome.app.getDetails().version.split(".").slice(0, 2).join("" );
48 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");
49 setLinks("acceptableAdsExplanation", getDocLink("acceptable_ads", "criteria"), 76 setLinks("acceptableAdsExplanation", getDocLink("acceptable_ads", "criteria"),
50 backgroundPage.openOptions); 77 backgroundPage.openOptions);
51 78
52 initSocialLinks(); 79 initSocialLinks(variant);
53 80
54 var donateLink = document.getElementById("share-donate"); 81 var donateLink = document.getElementById("share-donate");
55 donateLink.href = getDocLink("donate") + "&variant=" + variant; 82 donateLink.href = getDocLink("donate") + "&variant=" + variant;
56 } 83 }
57 window.addEventListener("load", init, false); 84 window.addEventListener("load", init, false);
58 85
59 function setLinks(id) 86 function setLinks(id)
60 { 87 {
61 var element = document.getElementById(id); 88 var element = document.getElementById(id);
62 if (!element) 89 if (!element)
(...skipping 14 matching lines...) Expand all
77 } 104 }
78 } 105 }
79 } 106 }
80 107
81 function getDocLink(page, anchor) 108 function getDocLink(page, anchor)
82 { 109 {
83 return Prefs.documentation_link 110 return Prefs.documentation_link
84 .replace(/%LINK%/g, page) 111 .replace(/%LINK%/g, page)
85 .replace(/%LANG%/g, Utils.appLocale) + (anchor ? "#" + anchor : "" ); 112 .replace(/%LANG%/g, Utils.appLocale) + (anchor ? "#" + anchor : "" );
86 } 113 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld