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

Delta Between Two Patch Sets: popup.js

Issue 29317001: Relocated icon and redesigned icon popup (Closed)
Left Patch Set: Created Nov. 7, 2013, 5:44 p.m.
Right Patch Set: Merged setBadgeNumber and setBadgeBackgroundColor Created Dec. 13, 2013, 10:36 a.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-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 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 = chrome.extension.getBackgroundPage(); 18 var backgroundPage = ext.backgroundPage.getWindow();
19 var imports = ["require", "isWhitelisted", "extractHostFromURL", "refreshIconAnd ContextMenu", "openOptions"]; 19 var imports = ["require", "isWhitelisted", "extractHostFromURL", "refreshIconAnd ContextMenu", "openOptions"];
20 for (var i = 0; i < imports.length; i++) 20 for (var i = 0; i < imports.length; i++)
21 window[imports[i]] = backgroundPage[imports[i]]; 21 window[imports[i]] = backgroundPage[imports[i]];
22 22
23 var Filter = require("filterClasses").Filter; 23 var Filter = require("filterClasses").Filter;
24 var FilterStorage = require("filterStorage").FilterStorage; 24 var FilterStorage = require("filterStorage").FilterStorage;
25 var Prefs = require("prefs").Prefs; 25 var Prefs = require("prefs").Prefs;
26 26
27 var tab = null; 27 var tab = null;
28 28
29 function init() 29 function init()
30 { 30 {
31 // Mark page as local to hide non-relevant elements 31 // Mark page as local to hide non-relevant elements
32 chrome.tabs.query({ 32 ext.windows.getLastFocused(function(win)
33 active: true,
34 currentWindow: true
35 }, function(tabs)
36 { 33 {
37 if (tabs.length == 0) 34 win.getActiveTab(function(tab)
38 return; 35 {
39 36 if (!/^https?:\/\//.exec(tab.url))
40 if (!/^https?:\/\//.exec(tabs[0].url)) 37 document.body.classList.add("local");
41 document.body.classList.add("local"); 38 });
42 }); 39 });
43 40
44 // Attach event listeners 41 // Attach event listeners
45 document.getElementById("enabled").addEventListener("click", toggleEnabled, fa lse); 42 document.getElementById("enabled").addEventListener("click", toggleEnabled, fa lse);
46 document.getElementById("clickhide").addEventListener("click", activateClickHi de, false); 43 document.getElementById("clickhide").addEventListener("click", activateClickHi de, false);
47 document.getElementById("clickhide-cancel").addEventListener("click", cancelCl ickHide, false); 44 document.getElementById("clickhide-cancel").addEventListener("click", cancelCl ickHide, false);
48 document.getElementById("options").addEventListener("click", function() 45 document.getElementById("options").addEventListener("click", function()
49 { 46 {
50 openOptions(); 47 openOptions();
51 }, false); 48 }, false);
52 49
53 // Set up collapsing of menu items 50 // Set up collapsing of menu items
54 var collapsers = document.getElementsByClassName("collapse"); 51 var collapsers = document.getElementsByClassName("collapse");
55 for (var i = 0; i < collapsers.length; i++) 52 for (var i = 0; i < collapsers.length; i++)
56 { 53 {
57 collapsers[i].addEventListener("click", toggleCollapse.bind(collapsers[i]), true); 54 var collapser = collapsers[i];
58 if (Prefs[collapsers[i].dataset.option]) 55 collapser.addEventListener("click", toggleCollapse, false);
59 document.getElementById(collapsers[i].dataset.collapsable).classList.add(" collapsed"); 56 if (!Prefs[collapser.dataset.option])
57 document.getElementById(collapser.dataset.collapsable).classList.add("coll apsed");
60 } 58 }
61 59
62 // Ask content script whether clickhide is active. If so, show cancel button. 60 // Ask content script whether clickhide is active. If so, show cancel button.
63 // If that isn't the case, ask background.html whether it has cached filters. If so, 61 // If that isn't the case, ask background.html whether it has cached filters. If so,
64 // ask the user whether she wants those filters. 62 // ask the user whether she wants those filters.
65 // Otherwise, we are in default state. 63 // Otherwise, we are in default state.
66 chrome.windows.getCurrent(function(w) 64 ext.windows.getLastFocused(function(win)
67 { 65 {
68 chrome.tabs.getSelected(w.id, function(t) 66 win.getActiveTab(function(t)
69 { 67 {
70 tab = t; 68 tab = t;
71 document.getElementById("enabled").classList.toggle("off", isWhitelisted(t ab.url)); 69 document.getElementById("enabled").classList.toggle("off", isWhitelisted(t ab.url));
72 70
73 chrome.tabs.sendRequest(tab.id, {reqtype: "get-clickhide-state"}, function (response) 71 tab.sendMessage({type: "get-clickhide-state"}, function(response)
74 { 72 {
75 document.body.classList.toggle("clickhide-active", response.active); 73 document.body.classList.toggle("clickhide-active", response.active);
76 }); 74 });
77 }); 75 });
78 }); 76 });
79 } 77 }
80 window.addEventListener("DOMContentLoaded", init, false); 78 window.addEventListener("DOMContentLoaded", init, false);
81 79
82 function toggleEnabled() 80 function toggleEnabled()
83 { 81 {
84 var enabledButton = document.getElementById("enabled") 82 var enabledButton = document.getElementById("enabled")
85 var checked = enabledButton.classList.contains("off"); 83 var disabled = enabledButton.classList.toggle("off");
86 if (checked) 84 if (disabled)
85 {
86 var host = extractHostFromURL(tab.url).replace(/^www\./, "");
87 var filter = Filter.fromText("@@||" + host + "^$document");
88 if (filter.subscriptions.length && filter.disabled)
89 filter.disabled = false;
90 else
91 {
92 filter.disabled = false;
93 FilterStorage.addFilter(filter);
94 }
95 }
96 else
87 { 97 {
88 // Remove any exception rules applying to this URL 98 // Remove any exception rules applying to this URL
89 var filter = isWhitelisted(tab.url); 99 var filter = isWhitelisted(tab.url);
90 while (filter) 100 while (filter)
91 { 101 {
92 FilterStorage.removeFilter(filter); 102 FilterStorage.removeFilter(filter);
93 if (filter.subscriptions.length) 103 if (filter.subscriptions.length)
94 filter.disabled = true; 104 filter.disabled = true;
95 filter = isWhitelisted(tab.url); 105 filter = isWhitelisted(tab.url);
96 } 106 }
97 } 107 }
98 else 108
99 {
100 var host = extractHostFromURL(tab.url).replace(/^www\./, "");
101 var filter = Filter.fromText("@@||" + host + "^$document");
102 if (filter.subscriptions.length && filter.disabled)
103 filter.disabled = false;
104 else
105 {
106 filter.disabled = false;
107 FilterStorage.addFilter(filter);
108 }
109 }
110
111 enabledButton.classList.toggle("off");
112 refreshIconAndContextMenu(tab); 109 refreshIconAndContextMenu(tab);
113 } 110 }
114 111
115 function activateClickHide() 112 function activateClickHide()
116 { 113 {
117 document.body.classList.add("clickhide-active"); 114 document.body.classList.add("clickhide-active");
118 chrome.tabs.sendRequest(tab.id, {reqtype: "clickhide-activate"}); 115 tab.sendMessage({type: "clickhide-activate"});
119 116
120 // Close the popup after a few seconds, so user doesn't have to 117 // Close the popup after a few seconds, so user doesn't have to
121 activateClickHide.timeout = window.setTimeout(window.close, 5000); 118 activateClickHide.timeout = window.setTimeout(window.close, 5000);
122 } 119 }
123 120
124 function cancelClickHide() 121 function cancelClickHide()
125 { 122 {
126 if (activateClickHide.timeout) 123 if (activateClickHide.timeout)
127 { 124 {
128 window.clearTimeout(activateClickHide.timeout); 125 window.clearTimeout(activateClickHide.timeout);
129 activateClickHide.timeout = null; 126 activateClickHide.timeout = null;
130 } 127 }
131 document.body.classList.remove("clickhide-active"); 128 document.body.classList.remove("clickhide-active");
132 chrome.tabs.sendRequest(tab.id, {reqtype: "clickhide-deactivate"}); 129 tab.sendMessage({type: "clickhide-deactivate"});
133 } 130 }
134 131
135 function toggleCollapse(ev) 132 function toggleCollapse(event)
136 { 133 {
137 Prefs[this.dataset.option] = !Prefs[this.dataset.option]; 134 var collapser = event.currentTarget;
138 this.parentNode.classList.toggle("collapsed"); 135 Prefs[collapser.dataset.option] = !Prefs[collapser.dataset.option];
136 collapser.parentNode.classList.toggle("collapsed");
139 } 137 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld