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

Unified Diff: options.js

Issue 29337729: Issue 2374 - Implemented Tweaks section in options page (Closed)
Patch Set: Created Feb. 25, 2016, 5:50 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
Index: options.js
===================================================================
--- a/options.js
+++ b/options.js
@@ -588,6 +588,13 @@
document.body.setAttribute("data-tab",
element.getAttribute("data-tab"));
break;
+ case "toggle-pref":
+ ext.backgroundPage.sendMessage(
+ {
+ type: "prefs.toggle",
+ key: element.name
+ });
+ break;
case "update-all-subscriptions":
ext.backgroundPage.sendMessage(
{
@@ -676,6 +683,19 @@
}, false);
// Advanced tab
+ var tweaks = document.querySelectorAll("#tweaks button[role='checkbox'][name]");
+ tweaks = Array.prototype.map.call(tweaks, function(checkbox)
+ {
+ return checkbox.name;
+ });
+ tweaks.forEach(function(name)
+ {
+ getPref(name, function(value)
+ {
+ onPrefMessage(name, value);
+ });
+ });
+
var filterTextbox = document.querySelector("#custom-filters-add input");
placeholderValue = getMessage("options_customFilters_textbox_placeholder");
filterTextbox.setAttribute("placeholder", placeholderValue);
@@ -829,17 +849,12 @@
function getAcceptableAdsURL(callback)
{
- ext.backgroundPage.sendMessage(
- {
- type: "prefs.get",
- key: "subscriptions_exceptionsurl"
- },
- function(value)
+ getPref("subscriptions_exceptionsurl", function(value)
{
getAcceptableAdsURL = function(callback)
{
callback(value);
- }
+ };
getAcceptableAdsURL(callback);
});
}
@@ -939,6 +954,70 @@
}
}
+ function hidePref(key, value)
+ {
+ var element = document.querySelector("[name='" + key + "']");
+ if (!element)
+ return;
+
+ var parent = findParentData(element, "optional", true);
+ parent.setAttribute("aria-hidden", value);
+ }
+
+ function getPref(key, callback)
+ {
+ var checkPref = getPref.checks[key] || getPref.checkNone;
+ checkPref(function(isActive)
+ {
+ if (!isActive)
+ {
+ hidePref(key, !isActive);
+ return;
+ }
+
+ ext.backgroundPage.sendMessage(
+ {
+ type: "prefs.get",
+ key: key
+ }, callback);
+ });
+ }
+ getPref.checkNone = function(callback)
+ {
+ callback(true);
+ };
+ getPref.checks = {
saroyanm 2016/02/29 14:34:39 Detail: Opening braces should be on it's own row,
Thomas Greiner 2016/02/29 17:32:43 Done. We've never been consistent with that one be
+ notifications_ignoredcategories: function(callback)
+ {
+ getPref("notifications_showui", callback);
+ },
+ safari_contentblocker: function(callback)
+ {
+ ext.backgroundPage.sendMessage(
+ {
+ type: "app.get",
+ what: "features"
+ },
+ function(features)
+ {
+ callback(features.safariContentBlocker);
+ });
+ }
+ };
+
+ function onPrefMessage(key, value)
+ {
+ var checkbox = document.querySelector("[name='" + key + "']");
+ if (checkbox)
+ {
+ if (key == "notifications_ignoredcategories")
+ value = (value.indexOf("*") == -1);
+ checkbox.setAttribute("aria-checked", value);
+ }
+ else if (key == "notifications_showui")
+ hidePref(key, !value);
+ }
+
function onShareLinkClick(e)
{
e.preventDefault();
@@ -1001,6 +1080,9 @@
case "filters.listen":
onFilterMessage(message.action, message.args[0]);
break;
+ case "prefs.listen":
+ onPrefMessage(message.action, message.args[0]);
+ break;
case "subscriptions.listen":
onSubscriptionMessage(message.action, message.args[0]);
break;
@@ -1019,6 +1101,12 @@
});
ext.backgroundPage.sendMessage(
{
+ type: "prefs.listen",
+ filter: ["notifications_ignoredcategories", "notifications_showui",
+ "safari_contentblocker", "shouldShowBlockElementMenu"]
+ });
+ ext.backgroundPage.sendMessage(
+ {
type: "subscriptions.listen",
filter: ["added", "disabled", "homepage", "lastDownload", "removed", "title"]
});

Powered by Google App Engine
This is Rietveld