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

Delta Between Two Patch Sets: chrome/content/ui/popup.js

Issue 5294633391226880: issue 1435 - Port popup.html from Chrome/Safari/Opera to Firefox (Closed)
Left Patch Set: Created Oct. 2, 2014, 7:48 a.m.
Right Patch Set: Created Oct. 27, 2014, 9:40 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 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 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 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/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 var backgroundPage = ext.backgroundPage.getWindow(); 18 var backgroundPage = ext.backgroundPage.getWindow();
19 window["openOptions"] = backgroundPage["openOptions"]; 19 var openOptions = backgroundPage.openOptions;
20 var tab = null; 20 var page = null;
21 21
22 function init() 22 function init()
23 { 23 {
24 // Mark page as local to hide non-relevant elements 24 ext.pages.query({active: true, lastFocusedWindow: true}, function(pages)
25 ext.windows.getLastFocused(function(win)
26 { 25 {
27 win.getActiveTab(function(t) 26 page = pages[0];
27 if (page)
28 { 28 {
29 tab = t; 29 document.body.classList.toggle("local", !/^https?:\/\//.test(page.url));
30 document.body.classList.toggle("local", !/^https?:\/\//.test(tab.url)); 30
31 }); 31 // Ask content script whether clickhide is active. If so, show cancel butt on.
32 page.sendMessage({type: "get-clickhide-state"}, function(response)
33 {
34 if (response && response.active)
35 document.body.classList.add("clickhide-active");
36 });
37 }
32 }); 38 });
33 39
34 // Initialize features 40 // Initialize features
35 initClickHide(); 41 initClickHide();
36 initReportIssue(); 42 initReportIssue();
37 initBlockable(); 43 initBlockable();
38 44
39 document.getElementById("options").addEventListener("click", function() 45 document.getElementById("options").addEventListener("click", function()
40 { 46 {
41 openOptions(); 47 openOptions();
42 }, false); 48 }, false);
43 } 49 }
44 window.addEventListener("DOMContentLoaded", init, false); 50 window.addEventListener("DOMContentLoaded", init, false);
45 51
46 function initClickHide() 52 function initClickHide()
47 { 53 {
48 if (!("activateClickHide" in ext)) 54 if (!("activateClickHide" in ext))
49 return; 55 return;
50 56
51 var menuItemActivate = document.getElementById("clickhide"); 57 var menuItemActivate = document.getElementById("clickhide");
52 menuItemActivate.addEventListener("click", activateClickHide, false); 58 menuItemActivate.addEventListener("click", activateClickHide, false);
53 menuItemActivate.removeAttribute("hidden"); 59 menuItemActivate.removeAttribute("hidden");
54 var menuItemCancel = document.getElementById("clickhide-cancel"); 60 var menuItemCancel = document.getElementById("clickhide-cancel");
55 menuItemCancel.addEventListener("click", cancelClickHide, false); 61 menuItemCancel.addEventListener("click", cancelClickHide, false);
56 menuItemCancel.removeAttribute("hidden"); 62 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 } 63 }
71 64
72 function initReportIssue() 65 function initReportIssue()
73 { 66 {
74 if (!("reportIssue" in ext) || !ext.showReportIssue()) 67 if (!("reportIssue" in ext) || !ext.showReportIssue())
75 return; 68 return;
76 69
77 var menuItem = document.getElementById("report-issue"); 70 var menuItem = document.getElementById("report-issue");
78 menuItem.addEventListener("click", function() 71 menuItem.addEventListener("click", function()
79 { 72 {
80 ext.reportIssue(); 73 ext.reportIssue();
81 }, false); 74 }, false);
82 menuItem.removeAttribute("hidden"); 75 menuItem.removeAttribute("hidden");
83 } 76 }
84 77
85 function initBlockable() 78 function initBlockable()
86 { 79 {
87 if (!ext.showBlockable()) 80 if (!("openBlockable" in ext))
88 return; 81 return;
89 82
90 var menuItem = document.getElementById("blockable"); 83 var menuItem = document.getElementById("blockable");
84 menuItem.classList.toggle("open", ext.isBlockableOpen());
91 menuItem.addEventListener("click", function() 85 menuItem.addEventListener("click", function()
92 { 86 {
93 ext.openBlockable(); 87 ext.openBlockable();
94 }, false); 88 }, false);
95 menuItem.removeAttribute("hidden"); 89 menuItem.removeAttribute("hidden");
96 } 90 }
97 91
98 function activateClickHide() 92 function activateClickHide()
99 { 93 {
100 document.body.classList.add("clickhide-active"); 94 document.body.classList.add("clickhide-active");
101 ext.activateClickHide(true); 95 ext.activateClickHide(true);
102 96
103 // Close the popup after a few seconds, so user doesn't have to 97 // Close the popup after a few seconds, so user doesn't have to
104 activateClickHide.timeout = window.setTimeout(ext.closePopup, 5000); 98 activateClickHide.timeout = window.setTimeout(ext.closePopup, 5000);
105 } 99 }
106 100
107 function cancelClickHide() 101 function cancelClickHide()
108 { 102 {
109 if (activateClickHide.timeout) 103 if (activateClickHide.timeout)
110 { 104 {
111 window.clearTimeout(activateClickHide.timeout); 105 window.clearTimeout(activateClickHide.timeout);
112 activateClickHide.timeout = null; 106 activateClickHide.timeout = null;
113 } 107 }
114 document.body.classList.remove("clickhide-active"); 108 document.body.classList.remove("clickhide-active");
115 ext.activateClickHide(false); 109 ext.activateClickHide(false);
116 } 110 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld