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: Addressed Felix' comments Created Dec. 3, 2013, 12:04 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
(...skipping 24 matching lines...) Expand all
35 { 35 {
36 if (!/^https?:\/\//.exec(tab.url)) 36 if (!/^https?:\/\//.exec(tab.url))
37 document.body.classList.add("local"); 37 document.body.classList.add("local");
38 }); 38 });
39 }); 39 });
40 40
41 // Attach event listeners 41 // Attach event listeners
42 document.getElementById("enabled").addEventListener("click", toggleEnabled, fa lse); 42 document.getElementById("enabled").addEventListener("click", toggleEnabled, fa lse);
43 document.getElementById("clickhide").addEventListener("click", activateClickHi de, false); 43 document.getElementById("clickhide").addEventListener("click", activateClickHi de, false);
44 document.getElementById("clickhide-cancel").addEventListener("click", cancelCl ickHide, false); 44 document.getElementById("clickhide-cancel").addEventListener("click", cancelCl ickHide, false);
45 document.getElementById("options").addEventListener("click", openOptions, fals e); 45 document.getElementById("options").addEventListener("click", function()
46 {
47 openOptions();
48 }, false);
46 49
47 // Set up collapsing of menu items 50 // Set up collapsing of menu items
48 var collapsers = document.getElementsByClassName("collapse"); 51 var collapsers = document.getElementsByClassName("collapse");
49 for (var i = 0; i < collapsers.length; i++) 52 for (var i = 0; i < collapsers.length; i++)
50 { 53 {
51 var collapser = collapsers[i]; 54 var collapser = collapsers[i];
52 collapser.addEventListener("click", toggleCollapse.bind(collapser), true); 55 collapser.addEventListener("click", toggleCollapse, false);
53 if (Prefs[collapser.dataset.option]) 56 if (!Prefs[collapser.dataset.option])
54 document.getElementById(collapser.dataset.collapsable).classList.add("coll apsed"); 57 document.getElementById(collapser.dataset.collapsable).classList.add("coll apsed");
55 } 58 }
56 59
57 // 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.
58 // 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,
59 // ask the user whether she wants those filters. 62 // ask the user whether she wants those filters.
60 // Otherwise, we are in default state. 63 // Otherwise, we are in default state.
61 ext.windows.getLastFocused(function(win) 64 ext.windows.getLastFocused(function(win)
62 { 65 {
63 win.getActiveTab(function(t) 66 win.getActiveTab(function(t)
64 { 67 {
65 tab = t; 68 tab = t;
66 document.getElementById("enabled").classList.toggle("off", isWhitelisted(t ab.url)); 69 document.getElementById("enabled").classList.toggle("off", isWhitelisted(t ab.url));
67 70
68 tab.sendMessage({type: "get-clickhide-state"}, function(response) 71 tab.sendMessage({type: "get-clickhide-state"}, function(response)
69 { 72 {
70 document.body.classList.toggle("clickhide-active", response.active); 73 document.body.classList.toggle("clickhide-active", response.active);
71 }); 74 });
72 }); 75 });
73 }); 76 });
74 } 77 }
75 window.addEventListener("DOMContentLoaded", init, false); 78 window.addEventListener("DOMContentLoaded", init, false);
76 79
77 function toggleEnabled() 80 function toggleEnabled()
78 { 81 {
79 var enabledButton = document.getElementById("enabled") 82 var enabledButton = document.getElementById("enabled")
80 var checked = enabledButton.classList.contains("off"); 83 var disabled = enabledButton.classList.toggle("off");
81 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
82 { 97 {
83 // Remove any exception rules applying to this URL 98 // Remove any exception rules applying to this URL
84 var filter = isWhitelisted(tab.url); 99 var filter = isWhitelisted(tab.url);
85 while (filter) 100 while (filter)
86 { 101 {
87 FilterStorage.removeFilter(filter); 102 FilterStorage.removeFilter(filter);
88 if (filter.subscriptions.length) 103 if (filter.subscriptions.length)
89 filter.disabled = true; 104 filter.disabled = true;
90 filter = isWhitelisted(tab.url); 105 filter = isWhitelisted(tab.url);
91 } 106 }
92 } 107 }
93 else 108
94 {
95 var host = extractHostFromURL(tab.url).replace(/^www\./, "");
96 var filter = Filter.fromText("@@||" + host + "^$document");
97 if (filter.subscriptions.length && filter.disabled)
98 filter.disabled = false;
99 else
100 {
101 filter.disabled = false;
102 FilterStorage.addFilter(filter);
103 }
104 }
105
106 enabledButton.classList.toggle("off");
107 refreshIconAndContextMenu(tab); 109 refreshIconAndContextMenu(tab);
108 } 110 }
109 111
110 function activateClickHide() 112 function activateClickHide()
111 { 113 {
112 document.body.classList.add("clickhide-active"); 114 document.body.classList.add("clickhide-active");
113 tab.sendMessage({type: "clickhide-activate"}); 115 tab.sendMessage({type: "clickhide-activate"});
114 116
115 // 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
116 activateClickHide.timeout = window.setTimeout(window.close, 5000); 118 activateClickHide.timeout = window.setTimeout(window.close, 5000);
117 } 119 }
118 120
119 function cancelClickHide() 121 function cancelClickHide()
120 { 122 {
121 if (activateClickHide.timeout) 123 if (activateClickHide.timeout)
122 { 124 {
123 window.clearTimeout(activateClickHide.timeout); 125 window.clearTimeout(activateClickHide.timeout);
124 activateClickHide.timeout = null; 126 activateClickHide.timeout = null;
125 } 127 }
126 document.body.classList.remove("clickhide-active"); 128 document.body.classList.remove("clickhide-active");
127 tab.sendMessage({type: "clickhide-deactivate"}); 129 tab.sendMessage({type: "clickhide-deactivate"});
128 } 130 }
129 131
130 function toggleCollapse() 132 function toggleCollapse(event)
131 { 133 {
132 Prefs[this.dataset.option] = !Prefs[this.dataset.option]; 134 var collapser = event.currentTarget;
133 this.parentNode.classList.toggle("collapsed"); 135 Prefs[collapser.dataset.option] = !Prefs[collapser.dataset.option];
136 collapser.parentNode.classList.toggle("collapsed");
134 } 137 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld