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: Merged updateLanguageCollections function Created June 21, 2016, 12:42 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 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 ]); 384 ]);
385 collections.filterLists = new Collection( 385 collections.filterLists = new Collection(
386 [ 386 [
387 { 387 {
388 id: "all-filter-lists-table", 388 id: "all-filter-lists-table",
389 onClick: toggleDisableSubscription, 389 onClick: toggleDisableSubscription,
390 useOriginalTitle: true 390 useOriginalTitle: true
391 } 391 }
392 ]); 392 ]);
393 393
394 function updateLanguageCollections(subscription)
395 {
396 if (subscription.recommended == "ads")
397 {
398 if (subscription.disabled)
399 {
400 collections.allLangs.addItems(subscription);
401 collections.langs.removeItem(subscription);
402 }
403 else
404 {
405 collections.allLangs.removeItem(subscription);
406 collections.langs.addItems(subscription);
407 }
408 }
409 }
410
411 function addSubscription(subscription) 394 function addSubscription(subscription)
412 { 395 {
413 var collection; 396 var collection;
414 if (subscription.recommended) 397 if (subscription.recommended)
415 { 398 {
416 if (subscription.recommended != "ads") 399 if (subscription.recommended != "ads")
417 collection = collections.popular; 400 collection = collections.popular;
418 else if (subscription.disabled == false) 401 else if (subscription.disabled == false)
419 collection = collections.langs; 402 collection = collections.langs;
420 else 403 else
421 collection = collections.allLangs; 404 collection = collections.allLangs;
422 } 405 }
423 else if (subscription.url == acceptableAdsUrl) 406 else if (subscription.url == acceptableAdsUrl)
424 collection = collections.acceptableAds; 407 collection = collections.acceptableAds;
425 else 408 else
426 collection = collections.custom; 409 collection = collections.custom;
427 410
428 collection.addItems(subscription); 411 collection.addItems(subscription);
429 subscriptionsMap[subscription.url] = subscription; 412 subscriptionsMap[subscription.url] = subscription;
430 updateTooltips(); 413 updateTooltips();
431 } 414 }
432 415
433 function updateSubscription(subscription) 416 function updateSubscription(subscription)
434 { 417 {
435 var knownSubscription = subscriptionsMap[subscription.url];
436 for (var property in subscription)
437 {
438 if (property == "title" && subscription.recommended)
439 knownSubscription.originalTitle = subscription.title;
440 else
441 knownSubscription[property] = subscription[property];
442 }
443
444 for (var name in collections) 418 for (var name in collections)
445 collections[name].updateItem(knownSubscription); 419 collections[name].updateItem(subscription);
446
447 return knownSubscription;
448 } 420 }
449 421
450 function updateFilter(filter) 422 function updateFilter(filter)
451 { 423 {
452 var match = filter.text.match(/^@@\|\|([^\/:]+)\^\$document$/); 424 var match = filter.text.match(/^@@\|\|([^\/:]+)\^\$document$/);
453 if (match && !filtersMap[filter.text]) 425 if (match && !filtersMap[filter.text])
454 { 426 {
455 filter.title = match[1]; 427 filter.title = match[1];
456 collections.whitelist.addItems(filter); 428 collections.whitelist.addItems(filter);
457 } 429 }
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 collections.whitelist.removeItem(knownFilter); 894 collections.whitelist.removeItem(knownFilter);
923 collections.customFilters.removeItem(knownFilter); 895 collections.customFilters.removeItem(knownFilter);
924 delete filtersMap[filter.text]; 896 delete filtersMap[filter.text];
925 updateShareLink(); 897 updateShareLink();
926 break; 898 break;
927 } 899 }
928 } 900 }
929 901
930 function onSubscriptionMessage(action, subscription) 902 function onSubscriptionMessage(action, subscription)
931 { 903 {
904 if (subscription.url in subscriptionsMap)
905 {
906 var knownSubscription = subscriptionsMap[subscription.url];
907 for (var property in subscription)
908 {
909 if (property == "title" && knownSubscription.recommended)
910 knownSubscription.originalTitle = subscription.title;
911 else
912 knownSubscription[property] = subscription[property];
913 }
914 subscription = knownSubscription;
915 }
932 switch (action) 916 switch (action)
933 { 917 {
934 case "disabled": 918 case "disabled":
935 subscription = updateSubscription(subscription); 919 if (subscription.recommended == "ads")
936 updateLanguageCollections(subscription); 920 {
921 if (subscription.disabled == true)
922 {
923 collections.allLangs.addItems(subscription);
924 collections.langs.removeItem(subscription);
925 }
926 else
927 {
928 collections.allLangs.removeItem(subscription);
929 collections.langs.addItems(subscription);
930 }
931 }
932 updateSubscription(subscription);
937 break; 933 break;
938 case "downloading": 934 case "downloading":
939 case "downloadStatus": 935 case "downloadStatus":
940 case "homepage": 936 case "homepage":
941 case "lastDownload": 937 case "lastDownload":
942 case "title": 938 case "title":
943 updateSubscription(subscription); 939 updateSubscription(subscription);
944 break; 940 break;
945 case "added": 941 case "added":
946 if (subscription.url in subscriptionsMap) 942 if (subscription.recommended == "ads")
947 subscription = updateSubscription(subscription); 943 {
944 collections.allLangs.removeItem(subscription);
Thomas Greiner 2016/06/22 10:08:04 The subscription might be disabled when it's added
saroyanm 2016/06/22 12:31:59 Well spotted, done
945 collections.langs.addItems(subscription);
946 }
947 else if (subscription.url in subscriptionsMap)
948 updateSubscription(subscription);
948 else 949 else
949 addSubscription(subscription); 950 addSubscription(subscription);
950 951
951 collections.filterLists.addItems(subscription); 952 collections.filterLists.addItems(subscription);
952 updateLanguageCollections(subscription);
953 break; 953 break;
954 case "removed": 954 case "removed":
955 var knownSubscription = subscriptionsMap[subscription.url];
956
957 if (subscription.url == acceptableAdsUrl || subscription.recommended) 955 if (subscription.url == acceptableAdsUrl || subscription.recommended)
958 { 956 {
959 subscription.disabled = true; 957 subscription.disabled = true;
960 onSubscriptionMessage("disabled", subscription); 958 onSubscriptionMessage("disabled", subscription);
961 } 959 }
962 else 960 else
963 { 961 {
964 collections.custom.removeItem(knownSubscription); 962 collections.custom.removeItem(subscription);
965 delete subscriptionsMap[subscription.url]; 963 delete subscriptionsMap[subscription.url];
966 } 964 }
967 collections.filterLists.removeItem(knownSubscription); 965 collections.filterLists.removeItem(subscription);
968 break; 966 break;
969 } 967 }
970 968
971 updateShareLink(); 969 updateShareLink();
972 } 970 }
973 971
974 function hidePref(key, value) 972 function hidePref(key, value)
975 { 973 {
976 var element = document.querySelector("[data-pref='" + key + "']"); 974 var element = document.querySelector("[data-pref='" + key + "']");
977 if (element) 975 if (element)
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 }); 1196 });
1199 ext.backgroundPage.sendMessage( 1197 ext.backgroundPage.sendMessage(
1200 { 1198 {
1201 type: "subscriptions.listen", 1199 type: "subscriptions.listen",
1202 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1200 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1203 "title", "downloadStatus", "downloading"] 1201 "title", "downloadStatus", "downloading"]
1204 }); 1202 });
1205 1203
1206 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1204 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1207 })(); 1205 })();
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