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 18 matching lines...) Expand all Loading... |
29 var popupMessageListener = function(event) | 29 var popupMessageListener = function(event) |
30 { | 30 { |
31 var originFilter = Filter.fromText("||adblockplus.org^"); | 31 var originFilter = Filter.fromText("||adblockplus.org^"); |
32 if (!originFilter.matches(event.origin, "OTHER", null, null)) | 32 if (!originFilter.matches(event.origin, "OTHER", null, null)) |
33 return; | 33 return; |
34 | 34 |
35 var data = JSON.parse(event.data); | 35 var data = JSON.parse(event.data); |
36 iframe.width = data.width; | 36 iframe.width = data.width; |
37 iframe.height = data.height; | 37 iframe.height = data.height; |
38 popupMessageReceived = true; | 38 popupMessageReceived = true; |
39 removeListener(window, "message", popupMessageListener); | 39 window.removeEventListener("message", popupMessageListener); |
40 }; | 40 }; |
41 addListener(window, "message", popupMessageListener); | 41 window.addEventListener("message", popupMessageListener); |
42 | 42 |
43 var listenCount = 0; | 43 var listenCount = 0; |
44 var popupLoadListener = function() | 44 var popupLoadListener = function() |
45 { | 45 { |
46 if (popupMessageReceived) | 46 if (popupMessageReceived) |
47 { | 47 { |
48 iframe.className = "visible"; | 48 iframe.className = "visible"; |
49 | 49 |
50 var popupCloseListener = function() | 50 var popupCloseListener = function() |
51 { | 51 { |
52 iframe.className = glassPane.className = ""; | 52 iframe.className = glassPane.className = ""; |
53 removeListener(document, "click", popupCloseListener); | 53 document.removeEventListener("click", popupCloseListener); |
54 }; | 54 }; |
55 addListener(document, "click", popupCloseListener); | 55 document.addEventListener("click", popupCloseListener); |
56 } | 56 } |
57 else | 57 else |
58 { | 58 { |
59 // wait up to 5 seconds and close popup if no message received | 59 // wait up to 5 seconds and close popup if no message received |
60 if (++listenCount > 20) | 60 if (++listenCount > 20) |
61 { | 61 { |
62 glassPane.className = ""; | 62 glassPane.className = ""; |
63 removeListener(window, "message", popupMessageListener); | 63 window.removeEventListener("message", popupMessageListener); |
64 } | 64 } |
65 else | 65 else |
66 setTimeout(popupLoadListener, 250); | 66 setTimeout(popupLoadListener, 250); |
67 } | 67 } |
68 | 68 |
69 removeListener(iframe, "load", popupLoadListener); | 69 iframe.removeEventListener("load", popupLoadListener); |
70 }; | 70 }; |
71 addListener(iframe, "load", popupLoadListener); | 71 iframe.addEventListener("load", popupLoadListener); |
72 | 72 |
73 iframe.src = url; | 73 iframe.src = url; |
74 glassPane.className = "visible"; | 74 glassPane.className = "visible"; |
75 } | 75 } |
76 | 76 |
77 function initSocialLinks(variant) | 77 function initSocialLinks(variant) |
78 { | 78 { |
79 // Share popup doesn't work in <IE9 so don't show it | 79 // Share popup doesn't work in <IE9 so don't show it |
80 if (/MSIE [6-8]/.test(navigator.appVersion)) | 80 if (/MSIE [6-8]/.test(navigator.appVersion)) |
81 return; | 81 return; |
82 | 82 |
83 var networks = ["twitter", "facebook", "gplus"]; | 83 var networks = ["twitter", "facebook", "gplus"]; |
84 networks.forEach(function(network) | 84 networks.forEach(function(network) |
85 { | 85 { |
86 var link = document.getElementById("share-" + network + "-" + variant); | 86 var link = document.getElementById("share-" + network + "-" + variant); |
87 addListener(link, "click", function(e) | 87 link.addEventListener("click", function(e) |
88 { | 88 { |
89 e.preventDefault(); | 89 e.preventDefault(); |
90 openSharePopup(getDocLink("share-" + network) + "&variant=" + variant); | 90 openSharePopup(getDocLink("share-" + network) + "&variant=" + variant); |
91 }); | 91 }); |
92 }); | 92 }); |
93 } | 93 } |
94 | 94 |
95 function getDocLink(page) | 95 function getDocLink(page) |
96 { | 96 { |
97 return Prefs.documentation_link | 97 return Prefs.documentation_link |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 document.documentElement.className = classList.join(" "); | 130 document.documentElement.className = classList.join(" "); |
131 | 131 |
132 initTranslations(); | 132 initTranslations(); |
133 initSocialLinks(variant); | 133 initSocialLinks(variant); |
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 window.addEventListener("load", init); | 139 window.addEventListener("load", init); |
OLD | NEW |