| Index: chrome/content/ui/popup.js |
| =================================================================== |
| new file mode 100644 |
| --- /dev/null |
| +++ b/chrome/content/ui/popup.js |
| @@ -0,0 +1,110 @@ |
| +/* |
| + * This file is part of Adblock Plus <http://adblockplus.org/>, |
| + * Copyright (C) 2006-2014 Eyeo GmbH |
| + * |
| + * Adblock Plus is free software: you can redistribute it and/or modify |
| + * it under the terms of the GNU General Public License version 3 as |
| + * published by the Free Software Foundation. |
| + * |
| + * Adblock Plus is distributed in the hope that it will be useful, |
| + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| + * GNU General Public License for more details. |
| + * |
| + * You should have received a copy of the GNU General Public License |
| + * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| + */ |
| + |
| +var backgroundPage = ext.backgroundPage.getWindow(); |
| +window["openOptions"] = backgroundPage["openOptions"]; |
|
Thomas Greiner
2014/10/17 15:02:21
I guess this is a leftover from the loop that was
saroyanm
2014/10/21 13:39:21
Done.
|
| +var page = null; |
| + |
| +function init() |
| +{ |
| + ext.pages.query({active: true, lastFocusedWindow: true}, function(pages) |
| + { |
| + page = pages[0]; |
| + if (page) |
| + { |
| + document.body.classList.toggle("local", !/^https?:\/\//.test(page.url)); |
| + |
| + // Ask content script whether clickhide is active. If so, show cancel button. |
| + page.sendMessage({type: "get-clickhide-state"}, function(response) |
| + { |
| + if (response && response.active) |
| + document.body.classList.add("clickhide-active"); |
| + }); |
| + } |
| + }); |
| + |
| + // Initialize features |
| + initClickHide(); |
| + initReportIssue(); |
| + initBlockable(); |
| + |
| + document.getElementById("options").addEventListener("click", function() |
| + { |
| + openOptions(); |
| + }, false); |
| +} |
| +window.addEventListener("DOMContentLoaded", init, false); |
| + |
| +function initClickHide() |
| +{ |
| + if (!("activateClickHide" in ext)) |
| + return; |
| + |
| + var menuItemActivate = document.getElementById("clickhide"); |
| + menuItemActivate.addEventListener("click", activateClickHide, false); |
| + menuItemActivate.removeAttribute("hidden"); |
| + var menuItemCancel = document.getElementById("clickhide-cancel"); |
| + menuItemCancel.addEventListener("click", cancelClickHide, false); |
| + menuItemCancel.removeAttribute("hidden"); |
| +} |
| + |
| +function initReportIssue() |
| +{ |
| + if (!("reportIssue" in ext) || !ext.showReportIssue()) |
| + return; |
| + |
| + var menuItem = document.getElementById("report-issue"); |
| + menuItem.addEventListener("click", function() |
| + { |
| + ext.reportIssue(); |
| + }, false); |
| + menuItem.removeAttribute("hidden"); |
| +} |
| + |
| +function initBlockable() |
| +{ |
| + if (!("openBlockable" in ext)) |
| + return; |
| + |
| + var menuItem = document.getElementById("blockable"); |
| + menuItem.classList.toggle("open", ext.isBlockableOpen()); |
| + menuItem.addEventListener("click", function() |
| + { |
| + ext.openBlockable(); |
| + }, false); |
| + menuItem.removeAttribute("hidden"); |
| +} |
| + |
| +function activateClickHide() |
| +{ |
| + document.body.classList.add("clickhide-active"); |
| + ext.activateClickHide(true); |
| + |
| + // Close the popup after a few seconds, so user doesn't have to |
| + activateClickHide.timeout = window.setTimeout(ext.closePopup, 5000); |
| +} |
| + |
| +function cancelClickHide() |
| +{ |
| + if (activateClickHide.timeout) |
| + { |
| + window.clearTimeout(activateClickHide.timeout); |
| + activateClickHide.timeout = null; |
| + } |
| + document.body.classList.remove("clickhide-active"); |
| + ext.activateClickHide(false); |
| +} |