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: Rebased to 0e4b41190cf5 Created March 15, 2016, 2:43 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 | « 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
@@ -602,6 +602,13 @@
document.body.setAttribute("data-tab",
element.getAttribute("data-tab"));
break;
+ case "toggle-pref":
+ ext.backgroundPage.sendMessage(
+ {
+ type: "prefs.toggle",
+ key: findParentData(element, "pref", false)
+ });
+ break;
case "update-all-subscriptions":
ext.backgroundPage.sendMessage(
{
@@ -690,6 +697,19 @@
}, false);
// Advanced tab
+ var tweaks = document.querySelectorAll("#tweaks li[data-pref]");
+ tweaks = Array.prototype.map.call(tweaks, function(checkbox)
+ {
+ return checkbox.getAttribute("data-pref");
+ });
+ tweaks.forEach(function(key)
+ {
+ getPref(key, function(value)
+ {
+ onPrefMessage(key, value);
+ });
+ });
+
var filterTextbox = document.querySelector("#custom-filters-add input");
placeholderValue = getMessage("options_customFilters_textbox_placeholder");
filterTextbox.setAttribute("placeholder", placeholderValue);
@@ -846,17 +866,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);
});
}
@@ -956,6 +971,70 @@
}
}
+ function hidePref(key, value)
+ {
+ var element = document.querySelector("[data-pref='" + key + "']");
+ if (element)
+ element.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 =
+ {
+ 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 + "'] button[role='checkbox']");
+ 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();
@@ -1014,6 +1093,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;
@@ -1032,6 +1114,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"]
});
« no previous file with comments | « options.html ('k') | skin/options.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld