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. 29, 2016, 5:27 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
« messageResponder.js ('K') | « options.html ('k') | skin/options.css » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.getAttribute("data-pref")
+ });
+ break;
case "update-all-subscriptions":
ext.backgroundPage.sendMessage(
{
@@ -676,6 +683,19 @@
}, false);
// Advanced tab
+ var tweaks = document.querySelectorAll("#tweaks button[role='checkbox'][data-pref]");
+ tweaks = Array.prototype.map.call(tweaks, function(checkbox)
+ {
+ return checkbox.getAttribute("data-pref");
+ });
+ 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,71 @@
}
}
+ function hidePref(key, value)
+ {
+ var element = document.querySelector("[data-pref='" + 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)
saroyanm 2016/03/11 14:55:58 Detail: I assume you grouped the functions for rea
Thomas Greiner 2016/03/15 15:39:26 Done.
+ {
+ callback(true);
+ };
+ getPref.checks =
+ {
+ 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("[data-pref='" + key + "']");
+ if (checkbox)
+ {
+ if (key == "notifications_ignoredcategories")
+ value = (value.indexOf("*") == -1);
+ checkbox.setAttribute("aria-checked", value);
+ }
+ else if (key == "notifications_showui")
+ hidePref("notifications_ignoredcategories", !value);
+ }
+
function onShareLinkClick(e)
{
e.preventDefault();
@@ -1001,6 +1081,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 +1102,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"]
});
« messageResponder.js ('K') | « options.html ('k') | skin/options.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld