Index: popup.js |
=================================================================== |
--- a/popup.js |
+++ b/popup.js |
@@ -16,47 +16,70 @@ |
*/ |
var backgroundPage = ext.backgroundPage.getWindow(); |
-var imports = ["require", "isWhitelisted", "extractHostFromURL", "refreshIconAndContextMenu"]; |
+var imports = ["require", "isWhitelisted", "extractHostFromURL", "refreshIconAndContextMenu", "openOptions"]; |
for (var i = 0; i < imports.length; i++) |
window[imports[i]] = backgroundPage[imports[i]]; |
var Filter = require("filterClasses").Filter; |
var FilterStorage = require("filterStorage").FilterStorage; |
+var Prefs = require("prefs").Prefs; |
var tab = null; |
function init() |
{ |
+ // Mark page as local to hide non-relevant elements |
+ ext.windows.getLastFocused(function(win) |
+ { |
+ win.getActiveTab(function(tab) |
+ { |
+ if (!/^https?:\/\//.exec(tab.url)) |
+ document.body.classList.add("local"); |
+ }); |
+ }); |
+ |
// Attach event listeners |
- $("#enabled").click(toggleEnabled); |
- $("#clickHideButton").click(activateClickHide); |
- $("#cancelButton").click(cancelClickHide); |
- $("#optionsButton").click(openOptions); |
+ document.getElementById("enabled").addEventListener("click", toggleEnabled, false); |
+ document.getElementById("clickhide").addEventListener("click", activateClickHide, false); |
+ document.getElementById("clickhide-cancel").addEventListener("click", cancelClickHide, false); |
+ document.getElementById("options").addEventListener("click", function() |
Felix Dahlke
2013/12/02 15:45:58
Why not just |.addEventListener("click", openOptio
Thomas Greiner
2013/12/03 12:06:05
I try to avoid passing event parameters on to exte
Wladimir Palant
2013/12/03 12:55:43
Actually correct here - otherwise the event will b
Thomas Greiner
2013/12/04 10:44:50
Done.
|
+ { |
+ openOptions(); |
+ }, false); |
+ |
+ // Set up collapsing of menu items |
+ var collapsers = document.getElementsByClassName("collapse"); |
+ for (var i = 0; i < collapsers.length; i++) |
+ { |
+ collapsers[i].addEventListener("click", toggleCollapse.bind(collapsers[i]), true); |
Felix Dahlke
2013/12/02 15:45:58
Nit: Wouldn't hurt to assign collapsers[i] to a te
Thomas Greiner
2013/12/03 12:06:05
Done.
Wladimir Palant
2013/12/03 12:55:43
Better solution - add toggleCollapse as callback w
Thomas Greiner
2013/12/04 10:44:50
Done.
|
+ if (Prefs[collapsers[i].dataset.option]) |
+ document.getElementById(collapsers[i].dataset.collapsable).classList.add("collapsed"); |
Wladimir Palant
2013/12/03 12:55:43
Isn't the logic reversed here? I think it should b
Thomas Greiner
2013/12/04 10:44:50
Done.
|
+ } |
// Ask content script whether clickhide is active. If so, show cancel button. |
// If that isn't the case, ask background.html whether it has cached filters. If so, |
// ask the user whether she wants those filters. |
// Otherwise, we are in default state. |
- ext.windows.getLastFocused(function(win) { |
- win.getActiveTab(function(t) { |
+ ext.windows.getLastFocused(function(win) |
+ { |
+ win.getActiveTab(function(t) |
+ { |
tab = t; |
- document.getElementById("enabled").checked = !isWhitelisted(tab.url); |
- document.getElementById("enabledCheckboxAndLabel").style.display = "block"; |
+ document.getElementById("enabled").classList.toggle("off", isWhitelisted(tab.url)); |
- tab.sendMessage({type: "get-clickhide-state"}, function(response) { |
- if(response.active) |
- clickHideActiveStuff(); |
- else |
- clickHideInactiveStuff(); |
+ tab.sendMessage({type: "get-clickhide-state"}, function(response) |
+ { |
+ document.body.classList.toggle("clickhide-active", response.active); |
}); |
}); |
}); |
} |
-$(init); |
+window.addEventListener("DOMContentLoaded", init, false); |
function toggleEnabled() |
{ |
- var checked = document.getElementById("enabled").checked; |
+ var enabledButton = document.getElementById("enabled") |
+ var checked = enabledButton.classList.contains("off"); |
Wladimir Palant
2013/12/03 12:55:43
classList.toggle() returns the new value - no need
Thomas Greiner
2013/12/04 10:44:50
Done.
|
if (checked) |
{ |
// Remove any exception rules applying to this URL |
@@ -82,12 +105,13 @@ |
} |
} |
+ enabledButton.classList.toggle("off"); |
refreshIconAndContextMenu(tab); |
} |
function activateClickHide() |
{ |
- clickHideActiveStuff(); |
+ document.body.classList.add("clickhide-active"); |
tab.sendMessage({type: "clickhide-activate"}); |
// Close the popup after a few seconds, so user doesn't have to |
@@ -101,25 +125,12 @@ |
window.clearTimeout(activateClickHide.timeout); |
activateClickHide.timeout = null; |
} |
- clickHideInactiveStuff(); |
+ document.body.classList.remove("clickhide-active"); |
tab.sendMessage({type: "clickhide-deactivate"}); |
} |
-function openOptions() |
+function toggleCollapse(ev) |
Felix Dahlke
2013/12/02 15:45:58
The parameter is unused, might as well get rid of
Thomas Greiner
2013/12/03 12:06:05
Done.
Wladimir Palant
2013/12/03 12:55:43
As I said, it's better to use that parameter and r
Thomas Greiner
2013/12/04 10:44:50
Done.
|
{ |
- backgroundPage.openOptions(); |
+ Prefs[this.dataset.option] = !Prefs[this.dataset.option]; |
+ this.parentNode.classList.toggle("collapsed"); |
} |
- |
-function clickHideActiveStuff() |
-{ |
- document.getElementById("enabledCheckboxAndLabel").style.display = "none"; |
- document.getElementById("clickHideInactiveStuff").style.display = "none"; |
- document.getElementById("clickHideActiveStuff").style.display = "inherit"; |
-} |
- |
-function clickHideInactiveStuff() |
-{ |
- document.getElementById("enabledCheckboxAndLabel").style.display = "block"; |
- document.getElementById("clickHideActiveStuff").style.display = "none"; |
- document.getElementById("clickHideInactiveStuff").style.display = "inherit"; |
-} |