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

Unified Diff: popup.js

Issue 29317001: Relocated icon and redesigned icon popup (Closed)
Patch Set: Created Nov. 7, 2013, 5:44 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « popup.html ('k') | skin/background-main-hover.png » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: popup.js
===================================================================
--- a/popup.js
+++ b/popup.js
@@ -16,21 +16,48 @@
*/
var backgroundPage = chrome.extension.getBackgroundPage();
-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
+ chrome.tabs.query({
+ active: true,
+ currentWindow: true
+ }, function(tabs)
+ {
+ if (tabs.length == 0)
+ return;
+
+ if (!/^https?:\/\//.exec(tabs[0].url))
+ document.body.classList.add("local");
+ });
+
// Attach event listeners
- $("#enabled").click(toggleEnabled);
- $("#clickHideButton").click(activateClickHide);
- $("#cancelButton").click(cancelClickHide);
+ 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()
+ {
+ 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);
+ if (Prefs[collapsers[i].dataset.option])
+ document.getElementById(collapsers[i].dataset.collapsable).classList.add("collapsed");
+ }
// 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,
@@ -41,24 +68,21 @@
chrome.tabs.getSelected(w.id, 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));
chrome.tabs.sendRequest(tab.id, {reqtype: "get-clickhide-state"}, function(response)
{
- if(response.active)
- clickHideActiveStuff();
- else
- clickHideInactiveStuff();
+ 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");
if (checked)
{
// Remove any exception rules applying to this URL
@@ -84,12 +108,13 @@
}
}
+ enabledButton.classList.toggle("off");
refreshIconAndContextMenu(tab);
}
function activateClickHide()
{
- clickHideActiveStuff();
+ document.body.classList.add("clickhide-active");
chrome.tabs.sendRequest(tab.id, {reqtype: "clickhide-activate"});
// Close the popup after a few seconds, so user doesn't have to
@@ -103,20 +128,12 @@
window.clearTimeout(activateClickHide.timeout);
activateClickHide.timeout = null;
}
- clickHideInactiveStuff();
+ document.body.classList.remove("clickhide-active");
chrome.tabs.sendRequest(tab.id, {reqtype: "clickhide-deactivate"});
}
-function clickHideActiveStuff()
+function toggleCollapse(ev)
{
- document.getElementById("enabledCheckboxAndLabel").style.display = "none";
- document.getElementById("clickHideInactiveStuff").style.display = "none";
- document.getElementById("clickHideActiveStuff").style.display = "inherit";
+ Prefs[this.dataset.option] = !Prefs[this.dataset.option];
+ this.parentNode.classList.toggle("collapsed");
}
-
-function clickHideInactiveStuff()
-{
- document.getElementById("enabledCheckboxAndLabel").style.display = "block";
- document.getElementById("clickHideActiveStuff").style.display = "none";
- document.getElementById("clickHideInactiveStuff").style.display = "inherit";
-}
« 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