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

Unified Diff: firstRun.js

Issue 8615139: adblockpluschrome: Open share page in lightbox (Closed)
Patch Set: Created Oct. 24, 2012, 2:51 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « firstRun.html ('k') | skin/firstRun.css » ('j') | skin/firstRun.css » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: firstRun.js
===================================================================
--- a/firstRun.js
+++ b/firstRun.js
@@ -3,6 +3,62 @@
var Prefs = require("prefs").Prefs;
var Utils = require("utils").Utils;
+jQuery.fn.center = function()
+{
+ return this.css({
+ position: "absolute",
+ top: Math.max(0, (($(window).height() - this.outerHeight()) / 2)
+ + $(window).scrollTop()),
+ left: Math.max(0, (($(window).width() - this.outerWidth()) / 2)
+ + $(window).scrollLeft())
+ });
+};
+
+function openSharePopup(url)
+{
+ var glassPane = $("<div/>").addClass("share-popup-glass-pane");
+
+ var iframe = $("<iframe/>")
+ .addClass("share-popup")
+ .attr({
+ src: url,
+ scrolling: "no"
+ })
+ .on("load", function()
+ {
+ iframe.center().fadeIn(150);
+ $(document).click(function()
+ {
+ iframe.fadeOut(100, iframe.remove);
+ glassPane.fadeOut(200, glassPane.remove);
Wladimir Palant 2012/10/25 07:12:00 I think that using CSS transitions for fade-in/fad
+ });
+ });
Wladimir Palant 2012/10/25 07:12:00 Generally I'm trying to avoid creating non-trivial
+
+ var body = $(document.body);
+ body.append(glassPane);
+ 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
+ {
+ body.append(iframe);
+ });
+}
+
+function initSocialLinks(variant)
+{
+ var networks = ["twitter", "facebook"];
+ networks.forEach(function(network)
+ {
+ var links = document.getElementsByClassName("share-" + network);
+ for (var i = 0; i < links.length; i++)
+ $(links[i])
+ .attr("href", "#")
Wladimir Palant 2012/10/25 07:12:00 Why does this attribute need to be defined dynamic
+ .click(function(e)
+ {
+ e.preventDefault();
+ openSharePopup(getDocLink(network) + "&variant=" + variant);
+ });
+ });
+}
+
function init()
{
// Choose a share text variant randomly
@@ -24,13 +80,7 @@
setLinks("acceptableAdsExplanation", getDocLink("acceptable_ads", "criteria"),
backgroundPage.openOptions);
- var facebookLinks = document.getElementsByClassName("share-facebook");
- for (var i = 0; i < facebookLinks.length; i++)
- facebookLinks[i].href = getDocLink("facebook") + "&variant=" + variant;
-
- var twitterLinks = document.getElementsByClassName("share-twitter");
- for (var i = 0; i < twitterLinks.length; i++)
- twitterLinks[i].href = getDocLink("twitter") + "&variant=" + variant;
+ initSocialLinks(variant);
var donateLink = document.getElementById("share-donate");
donateLink.href = getDocLink("donate") + "&variant=" + variant;
« no previous file with comments | « firstRun.html ('k') | skin/firstRun.css » ('j') | skin/firstRun.css » ('J')

Powered by Google App Engine
This is Rietveld