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

Side by Side Diff: new-options.js

Issue 29346555: Issue 4156 - Adblocking filter only being removed in advanced tab fix (Closed)
Patch Set: Restricted duplications Created Aug. 1, 2016, 6:14 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 Collection.prototype._getItemTitle = function(item, i) 64 Collection.prototype._getItemTitle = function(item, i)
65 { 65 {
66 if (item.url == acceptableAdsUrl) 66 if (item.url == acceptableAdsUrl)
67 return getMessage("options_acceptableAds_description"); 67 return getMessage("options_acceptableAds_description");
68 if (this.details[i].useOriginalTitle && item.originalTitle) 68 if (this.details[i].useOriginalTitle && item.originalTitle)
69 return item.originalTitle; 69 return item.originalTitle;
70 return item.title || item.url || item.text; 70 return item.title || item.url || item.text;
71 }; 71 };
72 72
73 Collection.prototype.addItems = function() 73 Collection.prototype.addItems = function()
Thomas Greiner 2016/08/04 15:54:02 Note: We should really change this function to onl
saroyanm 2016/08/17 14:59:15 Done.
74 { 74 {
75 var length = Array.prototype.push.apply(this.items, arguments); 75 var itemsToAdd = [];
76 if (length == 0) 76 for (var i = 0; i < arguments.length; i++)
Thomas Greiner 2016/08/04 15:54:02 Detail: I don't mind omitting the braces for a sin
saroyanm 2016/08/17 14:59:15 This was fixed during previous comment implementat
77 if (this.items.indexOf(arguments[i]) == -1)
78 itemsToAdd.push(arguments[i]);
79
80 if (itemsToAdd.length == 0)
77 return; 81 return;
78 82
83 Array.prototype.push.apply(this.items, itemsToAdd);
79 this.items.sort(function(a, b) 84 this.items.sort(function(a, b)
80 { 85 {
81 // Make sure that Acceptable Ads is always last, since it cannot be 86 // Make sure that Acceptable Ads is always last, since it cannot be
82 // disabled, but only be removed. That way it's grouped together with 87 // disabled, but only be removed. That way it's grouped together with
83 // the "Own filter list" which cannot be disabled either at the bottom 88 // the "Own filter list" which cannot be disabled either at the bottom
84 // of the filter lists in the Advanced tab. 89 // of the filter lists in the Advanced tab.
85 if (a.url == acceptableAdsUrl) 90 if (a.url == acceptableAdsUrl)
86 return 1; 91 return 1;
87 if (b.url == acceptableAdsUrl) 92 if (b.url == acceptableAdsUrl)
88 return -1; 93 return -1;
89 94
90 var aTitle = this._getItemTitle(a, 0).toLowerCase(); 95 var aTitle = this._getItemTitle(a, 0).toLowerCase();
91 var bTitle = this._getItemTitle(b, 0).toLowerCase(); 96 var bTitle = this._getItemTitle(b, 0).toLowerCase();
92 return aTitle.localeCompare(bTitle); 97 return aTitle.localeCompare(bTitle);
93 }.bind(this)); 98 }.bind(this));
94 99
95 for (var j = 0; j < this.details.length; j++) 100 for (var j = 0; j < this.details.length; j++)
96 { 101 {
97 var table = E(this.details[j].id); 102 var table = E(this.details[j].id);
98 var template = table.querySelector("template"); 103 var template = table.querySelector("template");
99 for (var i = 0; i < arguments.length; i++) 104 for (var i = 0; i < itemsToAdd.length; i++)
100 { 105 {
101 var item = arguments[i]; 106 var item = itemsToAdd[i];
102 var listItem = document.createElement("li"); 107 var listItem = document.createElement("li");
103 listItem.appendChild(document.importNode(template.content, true)); 108 listItem.appendChild(document.importNode(template.content, true));
104 listItem.setAttribute("aria-label", this._getItemTitle(item, j)); 109 listItem.setAttribute("aria-label", this._getItemTitle(item, j));
105 listItem.setAttribute("data-access", item.url || item.text); 110 listItem.setAttribute("data-access", item.url || item.text);
106 listItem.setAttribute("role", "section"); 111 listItem.setAttribute("role", "section");
107 112
108 var label = listItem.querySelector(".display"); 113 var label = listItem.querySelector(".display");
109 if (item.recommended && label.hasAttribute("data-tooltip")) 114 if (item.recommended && label.hasAttribute("data-tooltip"))
110 { 115 {
111 var tooltipId = label.getAttribute("data-tooltip"); 116 var tooltipId = label.getAttribute("data-tooltip");
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 } 333 }
329 ]); 334 ]);
330 collections.filterLists = new Collection( 335 collections.filterLists = new Collection(
331 [ 336 [
332 { 337 {
333 id: "all-filter-lists-table", 338 id: "all-filter-lists-table",
334 useOriginalTitle: true 339 useOriginalTitle: true
335 } 340 }
336 ]); 341 ]);
337 342
338 function updateLanguageCollections(subscription) 343 function toggleShowLanguage(subscription)
339 { 344 {
340 if (subscription.recommended == "ads") 345 if (subscription.recommended == "ads")
341 { 346 {
342 if (subscription.disabled) 347 if (subscription.disabled == false)
Thomas Greiner 2016/08/04 15:54:03 Detail: Do we need to explicitly check for `false`
saroyanm 2016/08/17 14:59:15 This change was required because with latest chang
348 {
349 collections.allLangs.removeItem(subscription);
350 collections.langs.addItems(subscription);
351 }
352 else
343 { 353 {
344 collections.allLangs.addItems(subscription); 354 collections.allLangs.addItems(subscription);
345 collections.langs.removeItem(subscription); 355 collections.langs.removeItem(subscription);
346 } 356 }
347 else
348 {
349 collections.allLangs.removeItem(subscription);
350 collections.langs.addItems(subscription);
351 }
352 } 357 }
353 } 358 }
354 359
355 function addSubscription(subscription) 360 function addSubscription(subscription)
356 { 361 {
357 var collection; 362 var collection;
358 if (subscription.recommended) 363 if (subscription.recommended)
359 { 364 {
360 if (subscription.recommended != "ads") 365 if (subscription.recommended != "ads")
361 collection = collections.popular; 366 collection = collections.popular;
362 else if (subscription.disabled == false) 367 else if (subscription.disabled == false)
363 collection = collections.langs; 368 collection = collections.langs;
364 else 369 else
365 collection = collections.allLangs; 370 collection = collections.allLangs;
366 } 371 }
367 else if (subscription.url == acceptableAdsUrl) 372 else if (subscription.url == acceptableAdsUrl)
368 collection = collections.acceptableAds; 373 collection = collections.acceptableAds;
369 else 374 else
370 collection = collections.custom; 375 collection = collections.custom;
371 376
372 collection.addItems(subscription); 377 collection.addItems(subscription);
373 subscriptionsMap[subscription.url] = subscription; 378 subscriptionsMap[subscription.url] = subscription;
379 toggleShowLanguage(subscription);
374 updateTooltips(); 380 updateTooltips();
375 } 381 }
376 382
377 function updateSubscription(subscription) 383 function updateSubscription(subscription)
378 { 384 {
379 var knownSubscription = subscriptionsMap[subscription.url]; 385 for (var name in collections)
380 for (var property in subscription) 386 collections[name].updateItem(subscription);
381 {
382 if (property == "title" && subscription.recommended)
383 knownSubscription.originalTitle = subscription.title;
384 else
385 knownSubscription[property] = subscription[property];
386 }
387 387
388 for (var name in collections) 388 toggleShowLanguage(subscription);
389 collections[name].updateItem(knownSubscription);
390
391 return knownSubscription;
392 } 389 }
393 390
394 function updateFilter(filter) 391 function updateFilter(filter)
395 { 392 {
396 var match = filter.text.match(/^@@\|\|([^\/:]+)\^\$document$/); 393 var match = filter.text.match(/^@@\|\|([^\/:]+)\^\$document$/);
397 if (match && !filtersMap[filter.text]) 394 if (match && !filtersMap[filter.text])
398 { 395 {
399 filter.title = match[1]; 396 filter.title = match[1];
400 collections.whitelist.addItems(filter); 397 collections.whitelist.addItems(filter);
401 } 398 }
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 collections.whitelist.removeItem(knownFilter); 1016 collections.whitelist.removeItem(knownFilter);
1020 collections.customFilters.removeItem(knownFilter); 1017 collections.customFilters.removeItem(knownFilter);
1021 delete filtersMap[filter.text]; 1018 delete filtersMap[filter.text];
1022 updateShareLink(); 1019 updateShareLink();
1023 break; 1020 break;
1024 } 1021 }
1025 } 1022 }
1026 1023
1027 function onSubscriptionMessage(action, subscription) 1024 function onSubscriptionMessage(action, subscription)
1028 { 1025 {
1026 if (subscription.url in subscriptionsMap)
1027 {
1028 var knownSubscription = subscriptionsMap[subscription.url];
1029 for (var property in subscription)
1030 {
1031 if (property == "title" && knownSubscription.recommended)
1032 knownSubscription.originalTitle = subscription.title;
1033 else
1034 knownSubscription[property] = subscription[property];
1035 }
1036 subscription = knownSubscription;
1037 }
1029 switch (action) 1038 switch (action)
1030 { 1039 {
1031 case "disabled": 1040 case "disabled":
1032 subscription = updateSubscription(subscription); 1041 updateSubscription(subscription);
1033 updateLanguageCollections(subscription);
1034 break; 1042 break;
1035 case "downloading": 1043 case "downloading":
1036 case "downloadStatus": 1044 case "downloadStatus":
1037 case "homepage": 1045 case "homepage":
1038 case "lastDownload": 1046 case "lastDownload":
1039 case "title": 1047 case "title":
1040 updateSubscription(subscription); 1048 updateSubscription(subscription);
1041 break; 1049 break;
1042 case "added": 1050 case "added":
1043 if (subscription.url in subscriptionsMap) 1051 if (subscription.url in subscriptionsMap)
1044 subscription = updateSubscription(subscription); 1052 updateSubscription(subscription);
1045 else 1053 else
1046 addSubscription(subscription); 1054 addSubscription(subscription);
1047 1055
1048 collections.filterLists.addItems(subscription); 1056 collections.filterLists.addItems(subscription);
1049 updateLanguageCollections(subscription);
1050 break; 1057 break;
1051 case "removed": 1058 case "removed":
1052 var knownSubscription = subscriptionsMap[subscription.url];
1053 if (subscription.url == acceptableAdsUrl || subscription.recommended) 1059 if (subscription.url == acceptableAdsUrl || subscription.recommended)
1054 { 1060 {
1055 subscription.disabled = true; 1061 subscription.disabled = true;
1056 onSubscriptionMessage("disabled", subscription); 1062 onSubscriptionMessage("disabled", subscription);
1057 } 1063 }
1058 else 1064 else
1059 { 1065 {
1060 collections.custom.removeItem(knownSubscription); 1066 collections.custom.removeItem(subscription);
1061 delete subscriptionsMap[subscription.url]; 1067 delete subscriptionsMap[subscription.url];
1062 } 1068 }
1063 collections.filterLists.removeItem(knownSubscription); 1069 collections.filterLists.removeItem(subscription);
1064 break; 1070 break;
1065 } 1071 }
1066 1072
1067 updateShareLink(); 1073 updateShareLink();
1068 } 1074 }
1069 1075
1070 function hidePref(key, value) 1076 function hidePref(key, value)
1071 { 1077 {
1072 var element = document.querySelector("[data-pref='" + key + "']"); 1078 var element = document.querySelector("[data-pref='" + key + "']");
1073 if (element) 1079 if (element)
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1281 ext.backgroundPage.sendMessage( 1287 ext.backgroundPage.sendMessage(
1282 { 1288 {
1283 type: "subscriptions.listen", 1289 type: "subscriptions.listen",
1284 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1290 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1285 "title", "downloadStatus", "downloading"] 1291 "title", "downloadStatus", "downloading"]
1286 }); 1292 });
1287 1293
1288 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1294 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1289 window.addEventListener("hashchange", onHashChange, false); 1295 window.addEventListener("hashchange", onHashChange, false);
1290 })(); 1296 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld