OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 { | 96 { |
97 return Prefs.documentation_link | 97 return Prefs.documentation_link |
98 .replace(/%LINK%/g, page) | 98 .replace(/%LINK%/g, page) |
99 .replace(/%LANG%/g, Utils.appLocale); | 99 .replace(/%LANG%/g, Utils.appLocale); |
100 } | 100 } |
101 | 101 |
102 function initTranslations() | 102 function initTranslations() |
103 { | 103 { |
104 // Map message ID to HTML element ID | 104 // Map message ID to HTML element ID |
105 var mapping = { | 105 var mapping = { |
| 106 "aa-title": "first-run-aa-title", |
| 107 "aa-text": "first-run-aa-text", |
106 "title-main": "first-run-title-install", | 108 "title-main": "first-run-title-install", |
107 "i18n-features-heading": "first-run-features-heading", | |
108 "i18n-feature-betterSurfing": "first-run-feature-betterSurfing", | |
109 "i18n-feature-videoAds": "first-run-feature-videoAds", | |
110 "share-text1": "first-run-share1", | 109 "share-text1": "first-run-share1", |
111 "share-text2": "first-run-share2", | 110 "share-text2": "first-run-share2", |
112 "share-donate": "first-run-share2-donate", | 111 "share-donate": "first-run-share2-donate", |
113 "share2-connection": "first-run-share2-or" | 112 "share2-connection": "first-run-share2-or" |
114 }; | 113 }; |
115 | 114 |
116 document.title = AdblockPlus.getMessage("first-run", "first-run-title-install"
); | 115 document.title = AdblockPlus.getMessage("first-run", "first-run-title-install"
); |
117 for (var i in mapping) | 116 for (var i in mapping) |
118 { | 117 { |
119 var element = document.getElementById(i); | 118 var element = document.getElementById(i); |
120 element.innerText = AdblockPlus.getMessage("first-run", mapping[i]); | 119 setElementText(element, AdblockPlus.getMessage("first-run", mapping[i])); |
121 } | 120 } |
122 } | 121 } |
123 | 122 |
124 function init() | 123 function init() |
125 { | 124 { |
126 // Choose a share text variant randomly | 125 // Choose a share text variant randomly |
127 var variant = Math.floor(Math.random() * 2) + 1; | 126 var variant = Math.floor(Math.random() * 2) + 1; |
128 var classList = document.documentElement.className.split(" "); | 127 var classList = document.documentElement.className.split(" "); |
129 classList.push("share-variant-" + variant); | 128 classList.push("share-variant-" + variant); |
130 document.documentElement.className = classList.join(" "); | 129 document.documentElement.className = classList.join(" "); |
131 | 130 |
132 initTranslations(); | 131 initTranslations(); |
133 initSocialLinks(variant); | 132 initSocialLinks(variant); |
| 133 setLinks("aa-text", getDocLink("acceptable_ads_criteria"), "index.html"); |
134 | 134 |
135 var donateLink = document.getElementById("share-donate"); | 135 var donateLink = document.getElementById("share-donate"); |
136 donateLink.href = getDocLink("donate") + "&variant=" + variant; | 136 donateLink.href = getDocLink("donate") + "&variant=" + variant; |
137 } | 137 } |
138 | 138 |
| 139 // Inserts i18n strings into matching elements. Any inner HTML already in the |
| 140 // element is parsed as JSON and used as parameters to substitute into |
| 141 // placeholders in the i18n message. |
| 142 setElementText = function(element, elementHtml) |
| 143 { |
| 144 function processString(str, element) |
| 145 { |
| 146 var match = /^(.*?)<(a|strong)>(.*?)<\/\2>(.*)$/.exec(str); |
| 147 if (match) |
| 148 { |
| 149 processString(match[1], element); |
| 150 |
| 151 var e = document.createElement(match[2]); |
| 152 processString(match[3], e); |
| 153 element.appendChild(e); |
| 154 |
| 155 processString(match[4], element); |
| 156 } |
| 157 else |
| 158 element.appendChild(document.createTextNode(str)); |
| 159 } |
| 160 |
| 161 while (element.lastChild) |
| 162 element.removeChild(element.lastChild); |
| 163 processString(elementHtml, element); |
| 164 } |
| 165 |
| 166 |
| 167 function setLinks(id) |
| 168 { |
| 169 var element = document.getElementById(id); |
| 170 if (!element) |
| 171 { |
| 172 return; |
| 173 } |
| 174 |
| 175 var links = element.getElementsByTagName("a"); |
| 176 |
| 177 for (var i = 0; i < links.length && i < arguments.length - 1; i++) |
| 178 { |
| 179 var curArg = arguments[i + 1]; |
| 180 if (typeof curArg == "string") |
| 181 { |
| 182 links[i].href = curArg; |
| 183 links[i].setAttribute("target", "_blank"); |
| 184 } |
| 185 else if (typeof curArg == "function") |
| 186 { |
| 187 links[i].href = "javascript:void(0);"; |
| 188 links[i].addEventListener("click", curArg, false); |
| 189 } |
| 190 } |
| 191 } |
| 192 |
139 window.addEventListener("load", init); | 193 window.addEventListener("load", init); |
OLD | NEW |