| Index: options.js |
| diff --git a/options.js b/options.js |
| index 3055baa441154856edac4c5b9f556150d27fbb6c..f0793806d8906ecaf41fa75fcdf6d4851663dc57 100644 |
| --- a/options.js |
| +++ b/options.js |
| @@ -84,7 +84,7 @@ var delayedSubscriptionSelection = null; |
| var acceptableAdsUrl; |
| -// Loads options and sets UI elements accordingly |
| +// Loads options from localStorage and sets UI elements accordingly |
| function loadOptions() |
| { |
| // Set page title to i18n version of "Adblock Plus Options" |
| @@ -148,11 +148,38 @@ function loadOptions() |
| return ignoredcategories.indexOf("*") == -1; |
| } |
| }); |
| + initCheckbox("safariContentBlocker", {onChange: function(checkbox) |
| + { |
| + var restartMessage = document.getElementById("restart-safari"); |
| + restartMessage.hidden = true; |
| + |
| + // When the user has chosen to use the legacy APIs but Safari has disabled |
| + // them we need to show a "Please restart Safari" message. |
| + if (!checkbox.checked) |
|
Sebastian Noack
2016/05/12 11:12:22
As discussed with Thomas on the review for the rel
kzar
2016/05/17 15:15:38
I don't understand what you mean by "persistent lo
Sebastian Noack
2016/05/17 18:35:24
At the very least this logic is inconsistent with
kzar
2016/05/17 19:20:21
Acknowledged.
|
| + { |
| + ext.backgroundPage.sendMessage({type: "safari.contentBlockingActive"}, |
| + function (contentBlockingActive) |
| + { |
| + if (contentBlockingActive) |
| + restartMessage.hidden = false; |
| + }); |
| + } |
| + }}); |
| getInfo("features", function(features) |
| { |
| if (!features.devToolsPanel) |
| document.getElementById("showDevtoolsPanelContainer").hidden = true; |
| + |
| + // Only show the option for Safari content blocking API if the user is |
| + // running Safari and both the legacy and content blocking APIs are |
| + // available. |
| + document.getElementById("safariContentBlockerContainer").hidden = !( |
| + features.safariContentBlocker && |
| + typeof safari != "undefined" && |
| + "canLoad" in safari.self.tab && |
| + "onbeforeload" in Element.prototype |
| + ); |
| }); |
| getPref("notifications_showui", function(notifications_showui) |
| { |
| @@ -174,7 +201,7 @@ function loadOptions() |
| { |
| type: "prefs.listen", |
| filter: ["notifications_ignoredcategories", "notifications_showui", |
| - "safari_contentblocker", "show_devtools_panel", |
| + "safariContentBlocker", "show_devtools_panel", |
| "shouldShowBlockElementMenu"] |
| }); |
| ext.backgroundPage.sendMessage( |
| @@ -242,20 +269,27 @@ function initCheckbox(id, descriptor) |
| { |
| var checkbox = document.getElementById(id); |
| var key = descriptor && descriptor.key || id; |
| + var onChange; |
| + if (descriptor && descriptor.onChange) |
| + onChange = descriptor.onChange.bind(undefined, checkbox); |
| getPref(key, function(value) |
| { |
| if (descriptor && descriptor.get) |
| checkbox.checked = descriptor.get(value); |
| else |
| checkbox.checked = value; |
| + |
| + if (onChange) |
| + onChange(); |
| }); |
| checkbox.addEventListener("click", function() |
| { |
| - if (descriptor && descriptor.toggle) |
| - checkbox.checked = descriptor.toggle(); |
| togglePref(key); |
| }, false); |
| + |
| + if (onChange) |
| + checkbox.addEventListener("change", onChange); |
| } |
| function loadRecommendations() |
| @@ -505,7 +539,12 @@ function onPrefMessage(key, value) |
| var checkbox = document.getElementById(key); |
| if (checkbox) |
| + { |
| checkbox.checked = value; |
| + // Apparently modifying the checked attribute for a checkbox does not |
|
Sebastian Noack
2016/05/12 11:12:23
If you want to emulate user actions that's what th
kzar
2016/05/17 15:15:37
Calling .click() would also toggle the checkbox ri
Sebastian Noack
2016/05/17 18:35:25
I wonder whether the change listener is even neces
kzar
2016/05/17 19:20:21
We also need to call the logic when the checkbox i
Sebastian Noack
2016/05/18 07:03:29
Well, in the new options page we call the same fun
kzar
2016/05/18 08:02:48
Yes, I already do that here.
Sebastian Noack
2016/05/18 08:13:37
But why can't you put the logic simply here then i
kzar
2016/05/18 09:28:47
Oh I finally understand, I think you mean that we
Sebastian Noack
2016/05/18 10:07:24
I don't see how that makes anything more confusing
kzar
2016/05/18 10:43:40
Done.
|
| + // dispatch the change event automatically... |
| + checkbox.dispatchEvent(new Event("change")); |
| + } |
| } |
| function onFilterMessage(action, filter) |