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 Sept. 26, 2014, 12:48 p.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 20 var page = null;
21 var tab = null;
22 21
23 function init() 22 function init()
24 { 23 {
25 // Mark page as local to hide non-relevant elements 24 ext.pages.query({active: true, lastFocusedWindow: true}, function(pages)
26 ext.windows.getLastFocused(function(win)
27 { 25 {
28 win.getActiveTab(function(t) 26 page = pages[0];
27 if (page)
29 { 28 {
30 tab = t; 29 document.body.classList.toggle("local", !/^https?:\/\//.test(page.url));
31 30
32 if (!/^https?:\/\//.exec(tab.url)) 31 // Ask content script whether clickhide is active. If so, show cancel butt on.
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.
33 document.body.classList.add("local"); 32 page.sendMessage({type: "get-clickhide-state"}, function(response)
34 }); 33 {
34 if (response && response.active)
35 document.body.classList.add("clickhide-active");
36 });
37 }
35 }); 38 });
36 39
37 // Initialize features 40 // Initialize features
38 initClickHide(); 41 initClickHide();
39 initReportIssue(); 42 initReportIssue();
40 initBlockable(); 43 initBlockable();
41 44
42 document.getElementById("options").addEventListener("click", function() 45 document.getElementById("options").addEventListener("click", function()
43 { 46 {
44 openOptions(); 47 openOptions();
45 }, false); 48 }, false);
46 } 49 }
47 window.addEventListener("DOMContentLoaded", init, false); 50 window.addEventListener("DOMContentLoaded", init, false);
48 51
49 function initClickHide() 52 function initClickHide()
50 { 53 {
51 if (!("activateClickHide" in ext)) 54 if (!("activateClickHide" in ext))
52 return; 55 return;
53 56
54 var menuItem1 = document.getElementById("clickhide"); 57 var menuItemActivate = 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.
55 menuItem1.addEventListener("click", activateClickHide, false); 58 menuItemActivate.addEventListener("click", activateClickHide, false);
56 menuItem1.removeAttribute("hidden"); 59 menuItemActivate.removeAttribute("hidden");
57 var menuItem2 = document.getElementById("clickhide-cancel"); 60 var menuItemCancel = document.getElementById("clickhide-cancel");
58 menuItem2.addEventListener("click", cancelClickHide, false); 61 menuItemCancel.addEventListener("click", cancelClickHide, false);
59 menuItem2.removeAttribute("hidden"); 62 menuItemCancel.removeAttribute("hidden");
60
61 // Ask content script whether clickhide is active. If so, show cancel button.
62 // If that isn't the case, ask background.html whether it has cached filters. If so,
63 // ask the user whether she wants those filters.
64 // 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.
65 ext.windows.getLastFocused(function(win)
66 {
67 win.getActiveTab(function(tab)
68 {
69 tab.sendMessage({type: "get-clickhide-state"}, function(response)
70 {
71 if (response && response.active)
72 document.body.classList.add("clickhide-active");
73 });
74 });
75 });
76 } 63 }
77 64
78 function initReportIssue() 65 function initReportIssue()
79 { 66 {
80 if (!("reportIssue" in ext) || !ext.showReportIssue()) 67 if (!("reportIssue" in ext) || !ext.showReportIssue())
81 return; 68 return;
82 69
83 var menuItem = document.getElementById("report-issue"); 70 var menuItem = document.getElementById("report-issue");
84 menuItem.addEventListener("click", function() 71 menuItem.addEventListener("click", function()
85 { 72 {
86 ext.reportIssue(); 73 ext.reportIssue();
87 }, false); 74 }, false);
88 menuItem.removeAttribute("hidden"); 75 menuItem.removeAttribute("hidden");
89 } 76 }
90 77
91 function initBlockable() 78 function initBlockable()
92 { 79 {
93 if (!ext.showBlockable()) 80 if (!("openBlockable" in ext))
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.
94 return; 81 return;
95 82
96 var menuItem = document.getElementById("blockable"); 83 var menuItem = document.getElementById("blockable");
84 menuItem.classList.toggle("open", ext.isBlockableOpen());
97 menuItem.addEventListener("click", function() 85 menuItem.addEventListener("click", function()
98 { 86 {
99 ext.openBlockable(); 87 ext.openBlockable();
100 }, false); 88 }, false);
101 menuItem.removeAttribute("hidden"); 89 menuItem.removeAttribute("hidden");
102 } 90 }
103 91
104 function activateClickHide() 92 function activateClickHide()
105 { 93 {
106 document.body.classList.add("clickhide-active"); 94 document.body.classList.add("clickhide-active");
107 ext.activateClickHide(true); 95 ext.activateClickHide(true);
108 96
109 // 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
110 activateClickHide.timeout = window.setTimeout(ext.closePopup, 5000); 98 activateClickHide.timeout = window.setTimeout(ext.closePopup, 5000);
111 } 99 }
112 100
113 function cancelClickHide() 101 function cancelClickHide()
114 { 102 {
115 if (activateClickHide.timeout) 103 if (activateClickHide.timeout)
116 { 104 {
117 window.clearTimeout(activateClickHide.timeout); 105 window.clearTimeout(activateClickHide.timeout);
118 activateClickHide.timeout = null; 106 activateClickHide.timeout = null;
119 } 107 }
120 document.body.classList.remove("clickhide-active"); 108 document.body.classList.remove("clickhide-active");
121 ext.activateClickHide(false); 109 ext.activateClickHide(false);
122 } 110 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld