OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2013 Eyeo GmbH |
| 4 * |
| 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 |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 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/>. |
| 16 */ |
| 17 |
| 18 /* Mock Start */ |
| 19 var Messages = { |
| 20 "first-run-feature-betterSurfing": "Enjoy the web without annoying ads", |
| 21 "first-run-feature-videoAds": "Watch videos without commercial interruptions", |
| 22 "first-run-features-heading": "With Adblock Plus you can:", |
| 23 "first-run-share1": "Do you think Adblock Plus is worth sharing? Please do!", |
| 24 "first-run-share2": "Adblock Plus is free and open source. Please support us:"
, |
| 25 "first-run-share2-donate": "Donate", |
| 26 "first-run-share2-or": "or", |
| 27 "first-run-title-install": "Adblock Plus has been installed" |
| 28 }; |
| 29 |
| 30 var AdblockPlus = { |
| 31 require: function() |
| 32 { |
| 33 return { |
| 34 Filter: { |
| 35 fromText: function() |
| 36 { |
| 37 return { |
| 38 matches: function() |
| 39 { |
| 40 return true; |
| 41 } |
| 42 }; |
| 43 } |
| 44 }, |
| 45 Prefs: { |
| 46 documentation_link: "https://adblockplus.org/redirect?link=%LINK%&lang=%
LANG%" |
| 47 }, |
| 48 Utils: { |
| 49 appLocale: "en" |
| 50 } |
| 51 }; |
| 52 }, |
| 53 getMessage: function(key) |
| 54 { |
| 55 return Messages[key] || "[" + key + "]"; |
| 56 } |
| 57 }; |
| 58 /* Mock End */ |
| 59 |
| 60 var require = AdblockPlus.require; |
| 61 var Prefs = require("prefs").Prefs; |
| 62 var Utils = require("utils").Utils; |
| 63 var Filter = require("filterClasses").Filter; |
| 64 |
| 65 function addListener(object, type, listener) |
| 66 { |
| 67 // all IE versions require the use of attachEvent for message event to work |
| 68 if (type != "message" && "addEventListener" in object) |
| 69 object.addEventListener(type, listener, false); |
| 70 else |
| 71 { |
| 72 object.attachEvent("on" + type, function() |
| 73 { |
| 74 listener(event); |
| 75 }); |
| 76 } |
| 77 } |
| 78 |
| 79 function removeListener(object, type, listener) |
| 80 { |
| 81 // all IE versions require the use of detachEvent for message event to work |
| 82 if (type != "message" && "removeEventListener" in object) |
| 83 object.removeEventListener(type, listener); |
| 84 else |
| 85 object.detachEvent("on" + type, listener); |
| 86 } |
| 87 |
| 88 function openSharePopup(url) |
| 89 { |
| 90 var iframe = document.getElementById("share-popup"); |
| 91 var glassPane = document.getElementById("glass-pane"); |
| 92 var popupMessageReceived = false; |
| 93 |
| 94 var popupMessageListener = function(event) |
| 95 { |
| 96 var originFilter = Filter.fromText("||adblockplus.org^"); |
| 97 if (!originFilter.matches(event.origin, "OTHER", null, null)) |
| 98 return; |
| 99 |
| 100 var data = JSON.parse(event.data); |
| 101 iframe.width = data.width; |
| 102 iframe.height = data.height; |
| 103 popupMessageReceived = true; |
| 104 removeListener(window, "message", popupMessageListener); |
| 105 }; |
| 106 addListener(window, "message", popupMessageListener); |
| 107 |
| 108 var listenCount = 0; |
| 109 var popupLoadListener = function() |
| 110 { |
| 111 if (popupMessageReceived) |
| 112 { |
| 113 iframe.className = "visible"; |
| 114 |
| 115 var popupCloseListener = function() |
| 116 { |
| 117 iframe.className = glassPane.className = ""; |
| 118 removeListener(document, "click", popupCloseListener); |
| 119 }; |
| 120 addListener(document, "click", popupCloseListener); |
| 121 } |
| 122 else |
| 123 { |
| 124 // wait up to 5 seconds and close popup if no message received |
| 125 if (++listenCount > 20) |
| 126 { |
| 127 glassPane.className = ""; |
| 128 removeListener(window, "message", popupMessageListener); |
| 129 } |
| 130 else |
| 131 setTimeout(popupLoadListener, 250); |
| 132 } |
| 133 |
| 134 removeListener(iframe, "load", popupLoadListener); |
| 135 }; |
| 136 addListener(iframe, "load", popupLoadListener); |
| 137 |
| 138 iframe.src = url; |
| 139 glassPane.className = "visible"; |
| 140 } |
| 141 |
| 142 function initSocialLinks(variant) |
| 143 { |
| 144 // Share popup doesn't work in <IE9 so don't show it |
| 145 if (/MSIE [6-8]/.test(navigator.appVersion)) |
| 146 return; |
| 147 |
| 148 var networks = ["twitter", "facebook", "gplus"]; |
| 149 networks.forEach(function(network) |
| 150 { |
| 151 var link = document.getElementById("share-" + network + "-" + variant); |
| 152 addListener(link, "click", function(e) |
| 153 { |
| 154 e.preventDefault(); |
| 155 openSharePopup(getDocLink("share-" + network) + "&variant=" + variant); |
| 156 }); |
| 157 }); |
| 158 } |
| 159 |
| 160 function getDocLink(page) |
| 161 { |
| 162 return Prefs.documentation_link |
| 163 .replace(/%LINK%/g, page) |
| 164 .replace(/%LANG%/g, Utils.appLocale); |
| 165 } |
| 166 |
| 167 function initTranslations() |
| 168 { |
| 169 // Map message ID to HTML element ID |
| 170 var mapping = { |
| 171 "title-main": "first-run-title-install", |
| 172 "i18n-features-heading": "first-run-features-heading", |
| 173 "i18n-feature-betterSurfing": "first-run-feature-betterSurfing", |
| 174 "i18n-feature-videoAds": "first-run-feature-videoAds", |
| 175 "share-text1": "first-run-share1", |
| 176 "share-text2": "first-run-share2", |
| 177 "share-donate": "first-run-share2-donate", |
| 178 "share2-connection": "first-run-share2-or" |
| 179 }; |
| 180 |
| 181 document.title = AdblockPlus.getMessage("first-run-title-install"); |
| 182 for (var i in mapping) |
| 183 { |
| 184 var element = document.getElementById(i); |
| 185 element.innerText = AdblockPlus.getMessage(mapping[i]); |
| 186 } |
| 187 } |
| 188 |
| 189 function init() |
| 190 { |
| 191 // Choose a share text variant randomly |
| 192 var variant = Math.floor(Math.random() * 2) + 1; |
| 193 var classList = document.documentElement.className.split(" "); |
| 194 classList.push("share-variant-" + variant); |
| 195 document.documentElement.className = classList.join(" "); |
| 196 |
| 197 initTranslations(); |
| 198 initSocialLinks(variant); |
| 199 |
| 200 var donateLink = document.getElementById("share-donate"); |
| 201 donateLink.href = getDocLink("donate") + "&variant=" + variant; |
| 202 } |
| 203 |
| 204 addListener(window, "load", init); |
OLD | NEW |