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. 10, 2014, 11:36 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 /*
Thomas Greiner 2014/10/13 13:18:24 Keep in mind that at some point we need to merge t
saroyanm 2014/10/16 11:26:15 I guess would be nice to do it during backport, or
Thomas Greiner 2014/10/16 13:39:44 That's fine with me.
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 page = null;
Thomas Greiner 2014/10/13 13:18:24 I assume that in one of the later reviews this var
saroyanm 2014/10/16 11:26:15 I tried to keep it like in Chrome/safari/opera ver
Thomas Greiner 2014/10/16 13:39:44 No, that's not necessary then.
21
22 function init()
23 {
24 ext.pages.query({active: true, lastFocusedWindow: true}, function(pages)
25 {
26 page = pages[0];
27
28 document.body.classList.toggle("local", !/^https?:\/\//.test(page.url));
Thomas Greiner 2014/10/13 13:18:24 This will throw an error if the pages array is emp
saroyanm 2014/10/16 11:26:15 Done.
29
30 if (page)
31 {
32 // Ask content script whether clickhide is active. If so, show cancel butt on.
33 page.sendMessage({type: "get-clickhide-state"}, function(response)
34 {
35 if (response && response.active)
36 document.body.classList.add("clickhide-active");
37 });
38 }
39 });
40
41 // Initialize features
42 initClickHide();
43 initReportIssue();
44 initBlockable();
45
46 document.getElementById("options").addEventListener("click", function()
47 {
48 openOptions();
49 }, false);
50 }
51 window.addEventListener("DOMContentLoaded", init, false);
52
53 function initClickHide()
54 {
55 if (!("activateClickHide" in ext))
56 return;
57
58 var menuItemActivate = document.getElementById("clickhide");
59 menuItemActivate.addEventListener("click", activateClickHide, false);
60 menuItemActivate.removeAttribute("hidden");
61 var menuItemCancel = document.getElementById("clickhide-cancel");
62 menuItemCancel.addEventListener("click", cancelClickHide, false);
63 menuItemCancel.removeAttribute("hidden");
64 }
65
66 function initReportIssue()
67 {
68 if (!("reportIssue" in ext) || !ext.showReportIssue())
69 return;
70
71 var menuItem = document.getElementById("report-issue");
72 menuItem.addEventListener("click", function()
73 {
74 ext.reportIssue();
75 }, false);
76 menuItem.removeAttribute("hidden");
77 }
78
79 function initBlockable()
80 {
81 if (!("openBlockable" in ext))
82 return;
83
84 var menuItem = document.getElementById("blockable");
85 if (ext.isBlockableOpen())
86 menuItem = document.getElementById("blockable-close");
87
88 menuItem.addEventListener("click", function()
89 {
90 ext.openBlockable();
91 }, false);
92 menuItem.removeAttribute("hidden");
93 }
94
95 function activateClickHide()
96 {
97 document.body.classList.add("clickhide-active");
98 ext.activateClickHide(true);
99
100 // Close the popup after a few seconds, so user doesn't have to
101 activateClickHide.timeout = window.setTimeout(ext.closePopup, 5000);
102 }
103
104 function cancelClickHide()
105 {
106 if (activateClickHide.timeout)
107 {
108 window.clearTimeout(activateClickHide.timeout);
109 activateClickHide.timeout = null;
110 }
111 document.body.classList.remove("clickhide-active");
112 ext.activateClickHide(false);
113 }
OLDNEW

Powered by Google App Engine
This is Rietveld