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

Delta Between Two Patch Sets: html/static/js/firstRun.js

Issue 10989023: First-run page on Adblock Plus for IE (Closed)
Left Patch Set: Created June 25, 2013, 10:26 a.m.
Right Patch Set: Created July 12, 2013, 10:50 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « html/static/img/social/twitter-old.png ('k') | html/templates/firstRun.html » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
18 /* Mock Start */ 18 /* Mock Start */
19 var Messages = { 19 var Messages = {
20 "firstRun_feature_betterSurfing": "Enjoy the web without annoying ads", 20 "first-run-feature-betterSurfing": "Enjoy the web without annoying ads",
21 "firstRun_feature_videoAds": "Watch videos without commercial interruptions", 21 "first-run-feature-videoAds": "Watch videos without commercial interruptions",
22 "firstRun_features_heading": "With Adblock Plus you can:", 22 "first-run-features-heading": "With Adblock Plus you can:",
23 "firstRun_share1": "Do you think Adblock Plus is worth sharing? Please do!", 23 "first-run-share1": "Do you think Adblock Plus is worth sharing? Please do!",
24 "firstRun_share2": "Adblock Plus is free and open source. Please support us:", 24 "first-run-share2": "Adblock Plus is free and open source. Please support us:" ,
25 "firstRun_share2_donate": "Donate", 25 "first-run-share2-donate": "Donate",
26 "firstRun_share2_or": "or", 26 "first-run-share2-or": "or",
27 "firstRun_title_install": "Adblock Plus has been installed" 27 "first-run-title-install": "Adblock Plus has been installed"
28 }; 28 };
29 29
30 var AdblockPlus = { 30 var AdblockPlus = {
31 require: function() 31 require: function()
32 { 32 {
33 return { 33 return {
34 Filter: { 34 Filter: {
35 fromText: function() 35 fromText: function()
36 { 36 {
37 return { 37 return {
(...skipping 17 matching lines...) Expand all
55 return Messages[key] || "[" + key + "]"; 55 return Messages[key] || "[" + key + "]";
56 } 56 }
57 }; 57 };
58 /* Mock End */ 58 /* Mock End */
59 59
60 var require = AdblockPlus.require; 60 var require = AdblockPlus.require;
61 var Prefs = require("prefs").Prefs; 61 var Prefs = require("prefs").Prefs;
62 var Utils = require("utils").Utils; 62 var Utils = require("utils").Utils;
63 var Filter = require("filterClasses").Filter; 63 var Filter = require("filterClasses").Filter;
64 64
65 function addListener(object, type, listener, useCapture) 65 function addListener(object, type, listener)
Felix Dahlke 2013/07/11 11:11:14 Since you're always passing useCapture=false, I gu
Thomas Greiner 2013/07/12 10:52:52 Done.
66 { 66 {
67 if ("addEventListener" in object) 67 // all IE versions require the use of attachEvent for message event to work
68 object.addEventListener(type, listener, useCapture); 68 if (type != "message" && "addEventListener" in object)
69 object.addEventListener(type, listener, false);
69 else 70 else
70 { 71 {
71 object.attachEvent("on" + type, function() 72 object.attachEvent("on" + type, function()
72 { 73 {
73 listener(event); 74 listener(event);
74 }); 75 });
75 } 76 }
76 } 77 }
77 78
78 function removeListener(object, type, listener) 79 function removeListener(object, type, listener)
79 { 80 {
80 if ("removeEventListener" in object) 81 // all IE versions require the use of detachEvent for message event to work
82 if (type != "message" && "removeEventListener" in object)
81 object.removeEventListener(type, listener); 83 object.removeEventListener(type, listener);
82 else 84 else
83 object.detachEvent(type, listener); 85 object.detachEvent("on" + type, listener);
Thomas Greiner 2013/07/12 10:52:52 Spotted and fix this.
84 } 86 }
85 87
86 function openSharePopup(url) 88 function openSharePopup(url)
87 { 89 {
88 var iframe = document.getElementById("share-popup"); 90 var iframe = document.getElementById("share-popup");
89 var glassPane = document.getElementById("glass-pane"); 91 var glassPane = document.getElementById("glass-pane");
90 var popupMessageReceived = false; 92 var popupMessageReceived = false;
91 93
92 var popupMessageListener = function(event) 94 var popupMessageListener = function(event)
93 { 95 {
94 var originFilter = Filter.fromText("||adblockplus.org^"); 96 var originFilter = Filter.fromText("||adblockplus.org^");
95 if (!originFilter.matches(event.origin, "OTHER", null, null)) 97 if (!originFilter.matches(event.origin, "OTHER", null, null))
96 return; 98 return;
97 99
98 var data = JSON.parse(event.data); 100 var data = JSON.parse(event.data);
99 iframe.width = data.width; 101 iframe.width = data.width;
100 iframe.height = data.height; 102 iframe.height = data.height;
101 popupMessageReceived = true; 103 popupMessageReceived = true;
102 // all IE versions require the use of detachEvent for message event to work 104 removeListener(window, "message", popupMessageListener);
103 window.detachEvent("onmessage", popupMessageListener);
104 }; 105 };
105 // all IE versions require the use of attachEvent for message event to work 106 addListener(window, "message", popupMessageListener);
106 window.attachEvent("onmessage", popupMessageListener); 107
Felix Dahlke 2013/07/11 11:11:14 So you're not using addEventListener here because
Thomas Greiner 2013/07/12 10:52:52 Done.
107 108 var listenCount = 0;
108 var timeout = 125;
Felix Dahlke 2013/07/11 11:11:14 I think the timeout calculating here is a bit more
Thomas Greiner 2013/07/12 10:52:52 Done.
109 var popupLoadListener = function() 109 var popupLoadListener = function()
110 { 110 {
111 if (popupMessageReceived) 111 if (popupMessageReceived)
112 { 112 {
113 iframe.className = "visible"; 113 iframe.className = "visible";
114 114
115 var popupCloseListener = function() 115 var popupCloseListener = function()
116 { 116 {
117 iframe.className = glassPane.className = ""; 117 iframe.className = glassPane.className = "";
118 removeListener(document, "click", popupCloseListener); 118 removeListener(document, "click", popupCloseListener);
119 }; 119 };
120 addListener(document, "click", popupCloseListener, false); 120 addListener(document, "click", popupCloseListener);
121 } 121 }
122 else 122 else
123 { 123 {
124 if (timeout > 2000) 124 // wait up to 5 seconds and close popup if no message received
125 if (++listenCount > 20)
125 { 126 {
126 glassPane.className = ""; 127 glassPane.className = "";
127 removeListener(window, "message", popupMessageListener); 128 removeListener(window, "message", popupMessageListener);
128 } 129 }
129 else 130 else
130 { 131 setTimeout(popupLoadListener, 250);
131 timeout *= 2;
132 setTimeout(popupLoadListener, timeout);
133 }
134 } 132 }
135 133
136 removeListener(iframe, "load", popupLoadListener); 134 removeListener(iframe, "load", popupLoadListener);
137 }; 135 };
138 addListener(iframe, "load", popupLoadListener, false); 136 addListener(iframe, "load", popupLoadListener);
139 137
140 iframe.src = url; 138 iframe.src = url;
141 glassPane.className = "visible"; 139 glassPane.className = "visible";
142 } 140 }
143 141
144 function initSocialLinks(variant) 142 function initSocialLinks(variant)
145 { 143 {
146 // Share popup doesn't work in <IE9 so don't show it 144 // Share popup doesn't work in <IE9 so don't show it
147 if (/MSIE [6-8]/.test(navigator.appVersion)) 145 if (/MSIE [6-8]/.test(navigator.appVersion))
148 return; 146 return;
149 147
150 var networks = ["twitter", "facebook", "gplus"]; 148 var networks = ["twitter", "facebook", "gplus"];
151 networks.forEach(function(network) 149 networks.forEach(function(network)
152 { 150 {
153 var link = document.getElementById("share-" + network + "-" + variant); 151 var link = document.getElementById("share-" + network + "-" + variant);
154 addListener(link, "click", function(e) 152 addListener(link, "click", function(e)
155 { 153 {
156 e.preventDefault(); 154 e.preventDefault();
157 openSharePopup(getDocLink("share-" + network) + "&variant=" + variant); 155 openSharePopup(getDocLink("share-" + network) + "&variant=" + variant);
158 }, false); 156 });
159 }); 157 });
160 } 158 }
161 159
162 function getDocLink(page) 160 function getDocLink(page)
163 { 161 {
164 return Prefs.documentation_link 162 return Prefs.documentation_link
165 .replace(/%LINK%/g, page) 163 .replace(/%LINK%/g, page)
166 .replace(/%LANG%/g, Utils.appLocale); 164 .replace(/%LANG%/g, Utils.appLocale);
167 } 165 }
168 166
169 function initTranslations() 167 function initTranslations()
170 { 168 {
171 // Map message ID to HTML element ID 169 // Map message ID to HTML element ID
172 var mapping = { 170 var mapping = {
173 "title-main": "firstRun_title_install", 171 "title-main": "first-run-title-install",
174 "i18n-features-heading": "firstRun_features_heading", 172 "i18n-features-heading": "first-run-features-heading",
175 "i18n-feature-betterSurfing": "firstRun_feature_betterSurfing", 173 "i18n-feature-betterSurfing": "first-run-feature-betterSurfing",
176 "i18n-feature-videoAds": "firstRun_feature_videoAds", 174 "i18n-feature-videoAds": "first-run-feature-videoAds",
177 "share-text1": "firstRun_share1", 175 "share-text1": "first-run-share1",
178 "share-text2": "firstRun_share2", 176 "share-text2": "first-run-share2",
179 "share-donate": "firstRun_share2_donate", 177 "share-donate": "first-run-share2-donate",
180 "share2-connection": "firstRun_share2_or" 178 "share2-connection": "first-run-share2-or"
181 }; 179 };
182 180
183 document.title = AdblockPlus.getMessage("firstRun_title_install"); 181 document.title = AdblockPlus.getMessage("first-run-title-install");
184 for (var i in mapping) 182 for (var i in mapping)
185 { 183 {
186 var element = document.getElementById(i); 184 var element = document.getElementById(i);
187 element.innerText = AdblockPlus.getMessage(mapping[i]); 185 element.innerText = AdblockPlus.getMessage(mapping[i]);
188 } 186 }
189 } 187 }
190 188
191 function init() 189 function init()
192 { 190 {
193 // Choose a share text variant randomly 191 // Choose a share text variant randomly
194 var variant = Math.floor(Math.random() * 2) + 1; 192 var variant = Math.floor(Math.random() * 2) + 1;
195 var classList = document.documentElement.className.split(" "); 193 var classList = document.documentElement.className.split(" ");
196 classList.push("share-variant-" + variant); 194 classList.push("share-variant-" + variant);
197 document.documentElement.className = classList.join(" "); 195 document.documentElement.className = classList.join(" ");
198 196
199 initTranslations(); 197 initTranslations();
200 initSocialLinks(variant); 198 initSocialLinks(variant);
201 199
202 var donateLink = document.getElementById("share-donate"); 200 var donateLink = document.getElementById("share-donate");
203 donateLink.href = getDocLink("donate") + "&variant=" + variant; 201 donateLink.href = getDocLink("donate") + "&variant=" + variant;
204 } 202 }
205 203
206 addListener(window, "load", init, false); 204 addListener(window, "load", init);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld