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

Unified Diff: html/static/js/firstRun.js

Issue 4812049892769792: Add acceptable ads message in FRP (Closed)
Patch Set: Don't use innerHTML assignment + OCD stuff Created July 24, 2014, 8:55 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
« no previous file with comments | « no previous file | html/templates/firstRun.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: html/static/js/firstRun.js
===================================================================
--- a/html/static/js/firstRun.js
+++ b/html/static/js/firstRun.js
@@ -103,10 +103,9 @@
{
// Map message ID to HTML element ID
var mapping = {
+ "aa-title": "first-run-aa-title",
+ "aa-text": "first-run-aa-text",
"title-main": "first-run-title-install",
- "i18n-features-heading": "first-run-features-heading",
- "i18n-feature-betterSurfing": "first-run-feature-betterSurfing",
- "i18n-feature-videoAds": "first-run-feature-videoAds",
"share-text1": "first-run-share1",
"share-text2": "first-run-share2",
"share-donate": "first-run-share2-donate",
@@ -117,7 +116,7 @@
for (var i in mapping)
{
var element = document.getElementById(i);
- element.innerText = AdblockPlus.getMessage("first-run", mapping[i]);
+ setElementText(element, AdblockPlus.getMessage("first-run", mapping[i]));
}
}
@@ -131,9 +130,66 @@
initTranslations();
initSocialLinks(variant);
+ setLinks("aa-text", getDocLink("acceptable_ads_criteria"), "index.html");
var donateLink = document.getElementById("share-donate");
donateLink.href = getDocLink("donate") + "&variant=" + variant;
}
+// Inserts i18n strings into matching elements. Any inner HTML already in the element is
Felix Dahlke 2014/07/24 09:04:49 Should wrap at 80 columns.
+// parsed as JSON and used as parameters to substitute into placeholders in the i18n
+// message.
+setElementText = function(element, elementHtml)
+{
+ function processString(str, element)
+ {
+ var match = /^(.*?)<(a|strong)>(.*?)<\/\2>(.*)$/.exec(str);
+ if (match)
+ {
+ processString(match[1], element);
+
+ var e = document.createElement(match[2]);
+ processString(match[3], e);
+ element.appendChild(e);
+
+ processString(match[4], element);
+ }
+ else
+ element.appendChild(document.createTextNode(str));
+ }
+
+ while (element.lastChild)
+ element.removeChild(element.lastChild);
+ processString(elementHtml, element);
+}
+
+
+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 (i >= (arguments.length - 1))
Felix Dahlke 2014/07/24 09:04:49 Why not add it to the for condition? Cleaner that
+ return;
+ var curArg = arguments[i + 1];
+ if (typeof curArg == "string")
+ {
+ links[i].href = curArg;
+ links[i].setAttribute("target", "_blank");
+ }
+ else if (typeof curArg == "function")
+ {
+ links[i].href = "javascript:void(0);";
+ links[i].addEventListener("click", curArg, false);
+ }
+ }
+}
+
window.addEventListener("load", init);
« no previous file with comments | « no previous file | html/templates/firstRun.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld