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

Side by Side Diff: popup.js

Issue 29317001: Relocated icon and redesigned icon popup (Closed)
Patch Set: Created Nov. 7, 2013, 5:44 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « popup.html ('k') | skin/background-main-hover.png » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 = chrome.extension.getBackgroundPage();
19 var imports = ["require", "isWhitelisted", "extractHostFromURL", "refreshIconAnd ContextMenu"]; 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 26
26 var tab = null; 27 var tab = null;
27 28
28 function init() 29 function init()
29 { 30 {
31 // Mark page as local to hide non-relevant elements
32 chrome.tabs.query({
33 active: true,
34 currentWindow: true
35 }, function(tabs)
36 {
37 if (tabs.length == 0)
38 return;
39
40 if (!/^https?:\/\//.exec(tabs[0].url))
41 document.body.classList.add("local");
42 });
43
30 // Attach event listeners 44 // Attach event listeners
31 $("#enabled").click(toggleEnabled); 45 document.getElementById("enabled").addEventListener("click", toggleEnabled, fa lse);
32 $("#clickHideButton").click(activateClickHide); 46 document.getElementById("clickhide").addEventListener("click", activateClickHi de, false);
33 $("#cancelButton").click(cancelClickHide); 47 document.getElementById("clickhide-cancel").addEventListener("click", cancelCl ickHide, false);
48 document.getElementById("options").addEventListener("click", function()
49 {
50 openOptions();
51 }, false);
52
53 // Set up collapsing of menu items
54 var collapsers = document.getElementsByClassName("collapse");
55 for (var i = 0; i < collapsers.length; i++)
56 {
57 collapsers[i].addEventListener("click", toggleCollapse.bind(collapsers[i]), true);
58 if (Prefs[collapsers[i].dataset.option])
59 document.getElementById(collapsers[i].dataset.collapsable).classList.add(" collapsed");
60 }
34 61
35 // Ask content script whether clickhide is active. If so, show cancel button. 62 // Ask content script whether clickhide is active. If so, show cancel button.
36 // If that isn't the case, ask background.html whether it has cached filters. If so, 63 // If that isn't the case, ask background.html whether it has cached filters. If so,
37 // ask the user whether she wants those filters. 64 // ask the user whether she wants those filters.
38 // Otherwise, we are in default state. 65 // Otherwise, we are in default state.
39 chrome.windows.getCurrent(function(w) 66 chrome.windows.getCurrent(function(w)
40 { 67 {
41 chrome.tabs.getSelected(w.id, function(t) 68 chrome.tabs.getSelected(w.id, function(t)
42 { 69 {
43 tab = t; 70 tab = t;
44 document.getElementById("enabled").checked = !isWhitelisted(tab.url); 71 document.getElementById("enabled").classList.toggle("off", isWhitelisted(t ab.url));
45 document.getElementById("enabledCheckboxAndLabel").style.display = "block" ;
46 72
47 chrome.tabs.sendRequest(tab.id, {reqtype: "get-clickhide-state"}, function (response) 73 chrome.tabs.sendRequest(tab.id, {reqtype: "get-clickhide-state"}, function (response)
48 { 74 {
49 if(response.active) 75 document.body.classList.toggle("clickhide-active", response.active);
50 clickHideActiveStuff();
51 else
52 clickHideInactiveStuff();
53 }); 76 });
54 }); 77 });
55 }); 78 });
56 } 79 }
57 $(init); 80 window.addEventListener("DOMContentLoaded", init, false);
58 81
59 function toggleEnabled() 82 function toggleEnabled()
60 { 83 {
61 var checked = document.getElementById("enabled").checked; 84 var enabledButton = document.getElementById("enabled")
85 var checked = enabledButton.classList.contains("off");
62 if (checked) 86 if (checked)
63 { 87 {
64 // Remove any exception rules applying to this URL 88 // Remove any exception rules applying to this URL
65 var filter = isWhitelisted(tab.url); 89 var filter = isWhitelisted(tab.url);
66 while (filter) 90 while (filter)
67 { 91 {
68 FilterStorage.removeFilter(filter); 92 FilterStorage.removeFilter(filter);
69 if (filter.subscriptions.length) 93 if (filter.subscriptions.length)
70 filter.disabled = true; 94 filter.disabled = true;
71 filter = isWhitelisted(tab.url); 95 filter = isWhitelisted(tab.url);
72 } 96 }
73 } 97 }
74 else 98 else
75 { 99 {
76 var host = extractHostFromURL(tab.url).replace(/^www\./, ""); 100 var host = extractHostFromURL(tab.url).replace(/^www\./, "");
77 var filter = Filter.fromText("@@||" + host + "^$document"); 101 var filter = Filter.fromText("@@||" + host + "^$document");
78 if (filter.subscriptions.length && filter.disabled) 102 if (filter.subscriptions.length && filter.disabled)
79 filter.disabled = false; 103 filter.disabled = false;
80 else 104 else
81 { 105 {
82 filter.disabled = false; 106 filter.disabled = false;
83 FilterStorage.addFilter(filter); 107 FilterStorage.addFilter(filter);
84 } 108 }
85 } 109 }
86 110
111 enabledButton.classList.toggle("off");
87 refreshIconAndContextMenu(tab); 112 refreshIconAndContextMenu(tab);
88 } 113 }
89 114
90 function activateClickHide() 115 function activateClickHide()
91 { 116 {
92 clickHideActiveStuff(); 117 document.body.classList.add("clickhide-active");
93 chrome.tabs.sendRequest(tab.id, {reqtype: "clickhide-activate"}); 118 chrome.tabs.sendRequest(tab.id, {reqtype: "clickhide-activate"});
94 119
95 // Close the popup after a few seconds, so user doesn't have to 120 // Close the popup after a few seconds, so user doesn't have to
96 activateClickHide.timeout = window.setTimeout(window.close, 5000); 121 activateClickHide.timeout = window.setTimeout(window.close, 5000);
97 } 122 }
98 123
99 function cancelClickHide() 124 function cancelClickHide()
100 { 125 {
101 if (activateClickHide.timeout) 126 if (activateClickHide.timeout)
102 { 127 {
103 window.clearTimeout(activateClickHide.timeout); 128 window.clearTimeout(activateClickHide.timeout);
104 activateClickHide.timeout = null; 129 activateClickHide.timeout = null;
105 } 130 }
106 clickHideInactiveStuff(); 131 document.body.classList.remove("clickhide-active");
107 chrome.tabs.sendRequest(tab.id, {reqtype: "clickhide-deactivate"}); 132 chrome.tabs.sendRequest(tab.id, {reqtype: "clickhide-deactivate"});
108 } 133 }
109 134
110 function clickHideActiveStuff() 135 function toggleCollapse(ev)
111 { 136 {
112 document.getElementById("enabledCheckboxAndLabel").style.display = "none"; 137 Prefs[this.dataset.option] = !Prefs[this.dataset.option];
113 document.getElementById("clickHideInactiveStuff").style.display = "none"; 138 this.parentNode.classList.toggle("collapsed");
114 document.getElementById("clickHideActiveStuff").style.display = "inherit";
115 } 139 }
116
117 function clickHideInactiveStuff()
118 {
119 document.getElementById("enabledCheckboxAndLabel").style.display = "block";
120 document.getElementById("clickHideActiveStuff").style.display = "none";
121 document.getElementById("clickHideInactiveStuff").style.display = "inherit";
122 }
OLDNEW
« no previous file with comments | « popup.html ('k') | skin/background-main-hover.png » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld