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

Unified Diff: chrome/content/ui/popup.js

Issue 5294633391226880: issue 1435 - Port popup.html from Chrome/Safari/Opera to Firefox (Closed)
Patch Set: Created Sept. 26, 2014, 12:48 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/content/ui/popup.js
===================================================================
new file mode 100644
--- /dev/null
+++ b/chrome/content/ui/popup.js
@@ -0,0 +1,122 @@
+/*
+ * 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"];
+
+var tab = null;
+
+function init()
+{
+ // Mark page as local to hide non-relevant elements
+ ext.windows.getLastFocused(function(win)
+ {
+ win.getActiveTab(function(t)
+ {
+ tab = t;
+
+ if (!/^https?:\/\//.exec(tab.url))
Thomas Greiner 2014/09/29 16:19:49 You can replace both the check and the class assig
saroyanm 2014/10/02 07:53:56 Awesome! Didn't know about second attribute.
+ document.body.classList.add("local");
+ });
+ });
+
+ // 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 menuItem1 = document.getElementById("clickhide");
Thomas Greiner 2014/09/29 16:19:49 A bit more descriptive variable names would be nic
saroyanm 2014/10/02 07:53:56 Done.
+ menuItem1.addEventListener("click", activateClickHide, false);
+ menuItem1.removeAttribute("hidden");
+ var menuItem2 = document.getElementById("clickhide-cancel");
+ menuItem2.addEventListener("click", cancelClickHide, false);
+ menuItem2.removeAttribute("hidden");
+
+ // Ask content script whether clickhide is active. If so, show cancel button.
+ // If that isn't the case, ask background.html whether it has cached filters. If so,
+ // ask the user whether she wants those filters.
+ // Otherwise, we are in default state.
Thomas Greiner 2014/09/29 16:19:49 The description doesn't need to mention what's goi
saroyanm 2014/10/02 07:53:56 Done.
+ ext.windows.getLastFocused(function(win)
+ {
+ win.getActiveTab(function(tab)
+ {
+ tab.sendMessage({type: "get-clickhide-state"}, function(response)
+ {
+ if (response && response.active)
+ document.body.classList.add("clickhide-active");
+ });
+ });
+ });
+}
+
+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 (!ext.showBlockable())
Thomas Greiner 2014/09/29 16:19:49 In regard to my suggestion to get rid of showBlock
saroyanm 2014/10/02 07:53:56 I guess I'm not catching on this part. Can you ple
Thomas Greiner 2014/10/08 10:40:43 This menu item should always be shown on platforms
saroyanm 2014/10/10 12:05:58 Got it, please let me know if you think we can giv
Thomas Greiner 2014/10/13 13:18:23 The new implementation looks good.
+ return;
+
+ var menuItem = document.getElementById("blockable");
+ 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);
+}

Powered by Google App Engine
This is Rietveld