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

Unified Diff: firstRun.js

Issue 8403145: First attempt at creating a first-run page (Closed)
Patch Set: Now with downscaling for smaller screens Created Oct. 1, 2012, 5:56 a.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
Index: firstRun.js
===================================================================
new file mode 100644
--- /dev/null
+++ b/firstRun.js
@@ -0,0 +1,63 @@
+var backgroundPage = chrome.extension.getBackgroundPage();
+var require = backgroundPage.require;
+var Prefs = require("prefs").Prefs;
+var Utils = require("utils").Utils;
+
+function init()
+{
+ // Choose a share text variant randomly
+ var variant = Math.floor(Math.random() * 2) + 1;
+ document.documentElement.setAttribute("share-variant", variant);
+
+ // Set up page title
+ var titleId = (backgroundPage.isFirstRun ? "firstRun_title_install" : "firstRun_title_update");
+ var pageTitle = chrome.i18n.getMessage(titleId);
+ document.title = document.getElementById("title").textContent = pageTitle;
+
+ // Set up URLs
+ var versionID = chrome.app.getDetails().version.split(".").slice(0, 2).join("");
Felix Dahlke 2012/10/02 12:36:04 Shouldn't this be named versionId, analogous to ti
+ setLinks("improvementsFeature", "https://adblockplus.org/releases/adblock-plus-" + versionID + "-for-google-chrome-released");
+ setLinks("acceptableAdsExplanation", getDocLink("acceptable_ads"),
+ 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;
+
+ var donateLink = document.getElementById("share-donate");
+ donateLink.href = getDocLink("donate") + "&variant=" + variant;
+}
+window.addEventListener("load", init, false);
+
+function setLinks(id)
+{
+ var element = document.getElementById(id);
+ if (!element)
+ return;
+
+ var links = element.getElementsByTagName("a");
+ for (var i = 0; i < links.length; i++)
+ {
+ if (typeof arguments[i + 1] == "string")
+ {
+ links[i].href = arguments[i + 1];
+ links[i].setAttribute("target", "_blank");
+ }
+ else if (typeof arguments[i + 1] == "function")
+ {
+ links[i].href = "javascript:void(0);";
+ links[i].addEventListener("click", arguments[i + 1], false);
+ }
+ }
+}
+
+function getDocLink(page, anchor)
+{
+ return Prefs.documentation_link
+ .replace(/%LINK%/g, page)
+ .replace(/%LANG%/g, Utils.appLocale) + (anchor ? "#" + anchor : "");
+}

Powered by Google App Engine
This is Rietveld