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

Side by Side Diff: html/static/js/firstRun.js

Issue 11300014: Injecting libadblockplus into IE (Closed)
Patch Set: Created July 29, 2013, 5:30 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17 var require;
18 var require = AdblockPlus.require;
19 var Prefs = require("prefs").Prefs;
20 var Utils = require("utils").Utils;
21 var Filter = require("filterClasses").Filter;
22 18
23 function addListener(object, type, listener) 19 function addListener(object, type, listener)
24 { 20 {
25 // all IE versions require the use of attachEvent for message event to work 21 // all IE versions require the use of attachEvent for message event to work
26 if (type != "message" && "addEventListener" in object) 22 if (type != "message" && "addEventListener" in object)
27 object.addEventListener(type, listener, false); 23 object.addEventListener(type, listener, false);
28 else 24 else
29 { 25 {
30 object.attachEvent("on" + type, function() 26 object.attachEvent("on" + type, function()
31 { 27 {
32 listener(event); 28 listener(event);
33 }); 29 });
34 } 30 }
35 } 31 }
36 32
37 function removeListener(object, type, listener) 33 function removeListener(object, type, listener)
38 { 34 {
39 // all IE versions require the use of detachEvent for message event to work 35 // all IE versions require the use of detachEvent for message event to work
40 if (type != "message" && "removeEventListener" in object) 36 if (type != "message" && "removeEventListener" in object)
41 object.removeEventListener(type, listener); 37 object.removeEventListener(type, listener);
42 else 38 else
43 object.detachEvent("on" + type, listener); 39 object.detachEvent("on" + type, listener);
44 } 40 }
45 41
46 function openSharePopup(url) 42 function openSharePopup(url)
47 { 43 {
44 var Prefs = require("prefs").Prefs;
45 var Utils = require("utils").Utils;
46 var Filter = require("filterClasses").Filter;
47
48
48 var iframe = document.getElementById("share-popup"); 49 var iframe = document.getElementById("share-popup");
49 var glassPane = document.getElementById("glass-pane"); 50 var glassPane = document.getElementById("glass-pane");
50 var popupMessageReceived = false; 51 var popupMessageReceived = false;
51 52
52 var popupMessageListener = function(event) 53 var popupMessageListener = function(event)
53 { 54 {
55 var Filter = require("filterClasses").Filter;
54 var originFilter = Filter.fromText("||adblockplus.org^"); 56 var originFilter = Filter.fromText("||adblockplus.org^");
55 if (!originFilter.matches(event.origin, "OTHER", null, null)) 57 if (!originFilter.matches(event.origin, "OTHER", null, null))
56 return; 58 return;
57 59
58 var data = JSON.parse(event.data); 60 var data = JSON.parse(event.data);
59 iframe.width = data.width; 61 iframe.width = data.width;
60 iframe.height = data.height; 62 iframe.height = data.height;
61 popupMessageReceived = true; 63 popupMessageReceived = true;
62 removeListener(window, "message", popupMessageListener); 64 removeListener(window, "message", popupMessageListener);
63 }; 65 };
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 addListener(link, "click", function(e) 112 addListener(link, "click", function(e)
111 { 113 {
112 e.preventDefault(); 114 e.preventDefault();
113 openSharePopup(getDocLink("share-" + network) + "&variant=" + variant); 115 openSharePopup(getDocLink("share-" + network) + "&variant=" + variant);
114 }); 116 });
115 }); 117 });
116 } 118 }
117 119
118 function getDocLink(page) 120 function getDocLink(page)
119 { 121 {
122 var Prefs = require("prefs").Prefs;
123 var Utils = require("utils").Utils;
124
120 return Prefs.documentation_link 125 return Prefs.documentation_link
121 .replace(/%LINK%/g, page) 126 .replace(/%LINK%/g, page)
122 .replace(/%LANG%/g, Utils.appLocale); 127 .replace(/%LANG%/g, Utils.appLocale);
123 } 128 }
124 129
125 function initTranslations() 130 function initTranslations()
126 { 131 {
127 // Map message ID to HTML element ID 132 // Map message ID to HTML element ID
128 var mapping = { 133 var mapping = {
129 "title-main": "first-run-title-install", 134 "title-main": "first-run-title-install",
130 "i18n-features-heading": "first-run-features-heading", 135 "i18n-features-heading": "first-run-features-heading",
131 "i18n-feature-betterSurfing": "first-run-feature-betterSurfing", 136 "i18n-feature-betterSurfing": "first-run-feature-betterSurfing",
132 "i18n-feature-videoAds": "first-run-feature-videoAds", 137 "i18n-feature-videoAds": "first-run-feature-videoAds",
133 "share-text1": "first-run-share1", 138 "share-text1": "first-run-share1",
134 "share-text2": "first-run-share2", 139 "share-text2": "first-run-share2",
135 "share-donate": "first-run-share2-donate", 140 "share-donate": "first-run-share2-donate",
136 "share2-connection": "first-run-share2-or" 141 "share2-connection": "first-run-share2-or"
137 }; 142 };
138 143
139 document.title = AdblockPlus.getMessage("first-run-title-install"); 144 document.title = Settings.GetMessage("first-run", "first-run-title-install");
140 for (var i in mapping) 145 for (var i in mapping)
141 { 146 {
142 var element = document.getElementById(i); 147 var element = document.getElementById(i);
143 element.innerText = AdblockPlus.getMessage(mapping[i]); 148 element.innerText = Settings.GetMessage("first-run", mapping[i]);
144 } 149 }
145 } 150 }
146 151
147 function init() 152 function init()
148 { 153 {
154 require = function(p){
155 eval("var response = " + Settings.require(p) + ";");
156 return response;
157 }
158
149 // Choose a share text variant randomly 159 // Choose a share text variant randomly
150 var variant = Math.floor(Math.random() * 2) + 1; 160 var variant = Math.floor(Math.random() * 2) + 1;
151 var classList = document.documentElement.className.split(" "); 161 var classList = document.documentElement.className.split(" ");
152 classList.push("share-variant-" + variant); 162 classList.push("share-variant-" + variant);
153 document.documentElement.className = classList.join(" "); 163 document.documentElement.className = classList.join(" ");
154 164
155 initTranslations(); 165 initTranslations();
156 initSocialLinks(variant); 166 initSocialLinks(variant);
157 167
158 var donateLink = document.getElementById("share-donate"); 168 var donateLink = document.getElementById("share-donate");
159 donateLink.href = getDocLink("donate") + "&variant=" + variant; 169 donateLink.href = getDocLink("donate") + "&variant=" + variant;
160 } 170 }
161 171
162 addListener(window, "load", init); 172 addListener(window, "load", init);
OLDNEW
« no previous file with comments | « .hgsubstate ('k') | html/templates/firstRun.html » ('j') | html/templates/firstRun.html » ('J')

Powered by Google App Engine
This is Rietveld