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

Side by Side Diff: chrome/content/ui/popup.js

Issue 5294633391226880: issue 1435 - Port popup.html from Chrome/Safari/Opera to Firefox (Closed)
Patch Set: Created Oct. 2, 2014, 7:48 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 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 var backgroundPage = ext.backgroundPage.getWindow();
19 window["openOptions"] = backgroundPage["openOptions"];
20 var tab = null;
21
22 function init()
23 {
24 // Mark page as local to hide non-relevant elements
25 ext.windows.getLastFocused(function(win)
26 {
27 win.getActiveTab(function(t)
28 {
29 tab = t;
30 document.body.classList.toggle("local", !/^https?:\/\//.test(tab.url));
31 });
32 });
33
34 // Initialize features
35 initClickHide();
36 initReportIssue();
37 initBlockable();
38
39 document.getElementById("options").addEventListener("click", function()
40 {
41 openOptions();
42 }, false);
43 }
44 window.addEventListener("DOMContentLoaded", init, false);
45
46 function initClickHide()
47 {
48 if (!("activateClickHide" in ext))
49 return;
50
51 var menuItemActivate = document.getElementById("clickhide");
52 menuItemActivate.addEventListener("click", activateClickHide, false);
53 menuItemActivate.removeAttribute("hidden");
54 var menuItemCancel = document.getElementById("clickhide-cancel");
55 menuItemCancel.addEventListener("click", cancelClickHide, false);
56 menuItemCancel.removeAttribute("hidden");
57
58 // Ask content script whether clickhide is active. If so, show cancel button.
59 ext.windows.getLastFocused(function(win)
60 {
61 win.getActiveTab(function(tab)
62 {
63 tab.sendMessage({type: "get-clickhide-state"}, function(response)
64 {
65 if (response && response.active)
66 document.body.classList.add("clickhide-active");
67 });
68 });
69 });
70 }
71
72 function initReportIssue()
73 {
74 if (!("reportIssue" in ext) || !ext.showReportIssue())
75 return;
76
77 var menuItem = document.getElementById("report-issue");
78 menuItem.addEventListener("click", function()
79 {
80 ext.reportIssue();
81 }, false);
82 menuItem.removeAttribute("hidden");
83 }
84
85 function initBlockable()
86 {
87 if (!ext.showBlockable())
88 return;
89
90 var menuItem = document.getElementById("blockable");
91 menuItem.addEventListener("click", function()
92 {
93 ext.openBlockable();
94 }, false);
95 menuItem.removeAttribute("hidden");
96 }
97
98 function activateClickHide()
99 {
100 document.body.classList.add("clickhide-active");
101 ext.activateClickHide(true);
102
103 // Close the popup after a few seconds, so user doesn't have to
104 activateClickHide.timeout = window.setTimeout(ext.closePopup, 5000);
105 }
106
107 function cancelClickHide()
108 {
109 if (activateClickHide.timeout)
110 {
111 window.clearTimeout(activateClickHide.timeout);
112 activateClickHide.timeout = null;
113 }
114 document.body.classList.remove("clickhide-active");
115 ext.activateClickHide(false);
116 }
OLDNEW

Powered by Google App Engine
This is Rietveld