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

Delta Between Two Patch Sets: options.js

Issue 29340571: Issue 3687 - Add experimental support for Safari content blockers (Closed)
Left Patch Set: Created April 19, 2016, 1:59 p.m.
Right Patch Set: Addressed Nits Created May 18, 2016, 11:30 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « options.html ('k') | popup.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 // Display jQuery UI elements 134 // Display jQuery UI elements
135 $("#tabs").tabs(); 135 $("#tabs").tabs();
136 $("button").button(); 136 $("button").button();
137 $(".refreshButton").button("option", "icons", {primary: "ui-icon-refresh"}); 137 $(".refreshButton").button("option", "icons", {primary: "ui-icon-refresh"});
138 $(".addButton").button("option", "icons", {primary: "ui-icon-plus"}); 138 $(".addButton").button("option", "icons", {primary: "ui-icon-plus"});
139 $(".removeButton").button("option", "icons", {primary: "ui-icon-minus"}); 139 $(".removeButton").button("option", "icons", {primary: "ui-icon-minus"});
140 140
141 // Popuplate option checkboxes 141 // Popuplate option checkboxes
142 initCheckbox("shouldShowBlockElementMenu"); 142 initCheckbox("shouldShowBlockElementMenu");
143 initCheckbox("show_devtools_panel"); 143 initCheckbox("show_devtools_panel");
144 initCheckbox("shouldShowNotifications", { 144 initCheckbox("shouldShowNotifications", "notifications_ignoredcategories");
145 key: "notifications_ignoredcategories", 145 initCheckbox("safariContentBlocker");
146 get: function(ignoredcategories)
147 {
148 return ignoredcategories.indexOf("*") == -1;
149 }
150 });
151 initCheckbox("safariContentBlocker", {onChange: function(checkbox)
152 {
153 var restartMessage = document.getElementById("restart-safari");
154 restartMessage.hidden = true;
155
156 // When the user has chosen to use the legacy APIs but Safari has disabled
157 // them we need to show a "Please restart Safari" message.
158 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.
159 {
160 ext.backgroundPage.sendMessage({type: "safari.contentBlockingActive"},
161 function (contentBlockingActive)
162 {
163 if (contentBlockingActive)
164 restartMessage.hidden = false;
165 });
166 }
167 }});
168 146
169 getInfo("features", function(features) 147 getInfo("features", function(features)
170 { 148 {
171 if (!features.devToolsPanel) 149 if (!features.devToolsPanel)
172 document.getElementById("showDevtoolsPanelContainer").hidden = true; 150 document.getElementById("showDevtoolsPanelContainer").hidden = true;
173 151
174 // Only show the option for Safari content blocking API if the user is 152 // Only show the option for Safari content blocking API if the user is
175 // running Safari and both the legacy and content blocking APIs are 153 // running Safari and both the legacy and content blocking APIs are
176 // available. 154 // available.
177 document.getElementById("safariContentBlockerContainer").hidden = !( 155 document.getElementById("safariContentBlockerContainer").hidden = !(
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 getSubscriptions(false, true, function(subscriptions) 236 getSubscriptions(false, true, function(subscriptions)
259 { 237 {
260 clearListBox("userFiltersBox"); 238 clearListBox("userFiltersBox");
261 clearListBox("excludedDomainsBox"); 239 clearListBox("excludedDomainsBox");
262 240
263 for (var i = 0; i < subscriptions.length; i++) 241 for (var i = 0; i < subscriptions.length; i++)
264 convertSpecialSubscription(subscriptions[i]); 242 convertSpecialSubscription(subscriptions[i]);
265 }); 243 });
266 } 244 }
267 245
268 function initCheckbox(id, descriptor) 246 function initCheckbox(id, key)
269 { 247 {
248 key = key || id;
270 var checkbox = document.getElementById(id); 249 var checkbox = document.getElementById(id);
271 var key = descriptor && descriptor.key || id; 250
272 var onChange;
273 if (descriptor && descriptor.onChange)
274 onChange = descriptor.onChange.bind(undefined, checkbox);
275 getPref(key, function(value) 251 getPref(key, function(value)
276 { 252 {
277 if (descriptor && descriptor.get) 253 onPrefMessage(key, value);
278 checkbox.checked = descriptor.get(value);
279 else
280 checkbox.checked = value;
281
282 if (onChange)
283 onChange();
284 }); 254 });
285 255
286 checkbox.addEventListener("click", function() 256 checkbox.addEventListener("click", function()
287 { 257 {
288 togglePref(key); 258 togglePref(key);
289 }, false); 259 }, false);
290
291 if (onChange)
292 checkbox.addEventListener("change", onChange);
293 } 260 }
294 261
295 function loadRecommendations() 262 function loadRecommendations()
296 { 263 {
297 fetch("subscriptions.xml") 264 fetch("subscriptions.xml")
298 .then(function(response) 265 .then(function(response)
299 { 266 {
300 return response.text(); 267 return response.text();
301 }) 268 })
302 .then(function(text) 269 .then(function(text)
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 { 495 {
529 switch (key) 496 switch (key)
530 { 497 {
531 case "notifications_showui": 498 case "notifications_showui":
532 document.getElementById("shouldShowNotificationsContainer").hidden = !valu e; 499 document.getElementById("shouldShowNotificationsContainer").hidden = !valu e;
533 return; 500 return;
534 case "notifications_ignoredcategories": 501 case "notifications_ignoredcategories":
535 key = "shouldShowNotifications"; 502 key = "shouldShowNotifications";
536 value = value.indexOf("*") == -1; 503 value = value.indexOf("*") == -1;
537 break; 504 break;
538 } 505 case "safariContentBlocker":
539 506 var restartMessage = document.getElementById("restart-safari");
507 restartMessage.hidden = true;
508 // When the user has chosen to use the legacy APIs but Safari has disabled
509 // them we need to show a "Please restart Safari" message.
510 if (!value)
511 {
512 ext.backgroundPage.sendMessage({type: "safari.contentBlockingActive"},
513 function(contentBlockingActive)
514 {
515 if (contentBlockingActive)
516 restartMessage.hidden = false;
517 });
518 }
519 }
540 var checkbox = document.getElementById(key); 520 var checkbox = document.getElementById(key);
541 if (checkbox) 521 if (checkbox)
542 {
543 checkbox.checked = value; 522 checkbox.checked = value;
544 // 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.
545 // dispatch the change event automatically...
546 checkbox.dispatchEvent(new Event("change"));
547 }
548 } 523 }
549 524
550 function onFilterMessage(action, filter) 525 function onFilterMessage(action, filter)
551 { 526 {
552 switch (action) 527 switch (action)
553 { 528 {
554 case "loaded": 529 case "loaded":
555 reloadFilters(); 530 reloadFilters();
556 break; 531 break;
557 case "added": 532 case "added":
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 onFilterMessage(message.action, message.args[0]); 762 onFilterMessage(message.action, message.args[0]);
788 break; 763 break;
789 case "prefs.respond": 764 case "prefs.respond":
790 onPrefMessage(message.action, message.args[0]); 765 onPrefMessage(message.action, message.args[0]);
791 break; 766 break;
792 case "subscriptions.respond": 767 case "subscriptions.respond":
793 onSubscriptionMessage(message.action, message.args[0]); 768 onSubscriptionMessage(message.action, message.args[0]);
794 break; 769 break;
795 } 770 }
796 }); 771 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld