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

Delta Between Two Patch Sets: new-options.js

Issue 29346555: Issue 4156 - Adblocking filter only being removed in advanced tab fix (Closed)
Left Patch Set: Rebased to changeset #87 Created Aug. 1, 2016, 6:10 p.m.
Right Patch Set: Changed addItems method to only accept 1 parameter and changed recommendations initial status Created Aug. 17, 2016, 2:55 p.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 | « no previous file | no next file » | 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 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.addItem = function(item)
74 { 74 {
75 var length = Array.prototype.push.apply(this.items, arguments); 75 if (this.items.indexOf(item) >= 0)
76 if (length == 0)
77 return; 76 return;
78 77
78 this.items.push(item);
79 this.items.sort(function(a, b) 79 this.items.sort(function(a, b)
80 { 80 {
81 // Make sure that Acceptable Ads is always last, since it cannot be 81 // 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 82 // 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 83 // the "Own filter list" which cannot be disabled either at the bottom
84 // of the filter lists in the Advanced tab. 84 // of the filter lists in the Advanced tab.
85 if (a.url == acceptableAdsUrl) 85 if (a.url == acceptableAdsUrl)
86 return 1; 86 return 1;
87 if (b.url == acceptableAdsUrl) 87 if (b.url == acceptableAdsUrl)
88 return -1; 88 return -1;
89 89
90 var aTitle = this._getItemTitle(a, 0).toLowerCase(); 90 var aTitle = this._getItemTitle(a, 0).toLowerCase();
91 var bTitle = this._getItemTitle(b, 0).toLowerCase(); 91 var bTitle = this._getItemTitle(b, 0).toLowerCase();
92 return aTitle.localeCompare(bTitle); 92 return aTitle.localeCompare(bTitle);
93 }.bind(this)); 93 }.bind(this));
94 94
95 for (var j = 0; j < this.details.length; j++) 95 for (var j = 0; j < this.details.length; j++)
96 { 96 {
97 var table = E(this.details[j].id); 97 var table = E(this.details[j].id);
98 var template = table.querySelector("template"); 98 var template = table.querySelector("template");
99 for (var i = 0; i < arguments.length; i++) 99 var listItem = document.createElement("li");
100 { 100 listItem.appendChild(document.importNode(template.content, true));
101 var item = arguments[i]; 101 listItem.setAttribute("aria-label", this._getItemTitle(item, j));
102 var listItem = document.createElement("li"); 102 listItem.setAttribute("data-access", item.url || item.text);
103 listItem.appendChild(document.importNode(template.content, true)); 103 listItem.setAttribute("role", "section");
104 listItem.setAttribute("aria-label", this._getItemTitle(item, j)); 104
105 listItem.setAttribute("data-access", item.url || item.text); 105 var label = listItem.querySelector(".display");
106 listItem.setAttribute("role", "section"); 106 if (item.recommended && label.hasAttribute("data-tooltip"))
107 107 {
108 var label = listItem.querySelector(".display"); 108 var tooltipId = label.getAttribute("data-tooltip");
109 if (item.recommended && label.hasAttribute("data-tooltip")) 109 tooltipId = tooltipId.replace("%value%", item.recommended);
110 { 110 label.setAttribute("data-tooltip", tooltipId);
111 var tooltipId = label.getAttribute("data-tooltip"); 111 }
112 tooltipId = tooltipId.replace("%value%", item.recommended); 112
113 label.setAttribute("data-tooltip", tooltipId); 113 var controls = listItem.querySelectorAll(".control");
114 for (var k = 0; k < controls.length; k++)
115 {
116 if (controls[k].hasAttribute("title"))
117 {
118 var titleValue = getMessage(controls[k].getAttribute("title"));
119 controls[k].setAttribute("title", titleValue)
114 } 120 }
115 121 }
116 var controls = listItem.querySelectorAll(".control"); 122
117 for (var k = 0; k < controls.length; k++) 123 this._setEmpty(table, null);
118 { 124 if (table.hasChildNodes())
119 if (controls[k].hasAttribute("title")) 125 {
120 { 126 table.insertBefore(listItem,
121 var titleValue = getMessage(controls[k].getAttribute("title")); 127 table.childNodes[this.items.indexOf(item)]);
122 controls[k].setAttribute("title", titleValue) 128 }
123 } 129 else
124 } 130 table.appendChild(listItem);
125 131 this.updateItem(item);
126 this._setEmpty(table, null);
127 if (table.hasChildNodes())
128 {
129 table.insertBefore(listItem,
130 table.childNodes[this.items.indexOf(item)]);
131 }
132 else
133 table.appendChild(listItem);
134 this.updateItem(item);
135 }
136 } 132 }
137 return length; 133 return length;
138 }; 134 };
139 135
140 Collection.prototype.removeItem = function(item) 136 Collection.prototype.removeItem = function(item)
141 { 137 {
142 var index = this.items.indexOf(item); 138 var index = this.items.indexOf(item);
143 if (index == -1) 139 if (index == -1)
144 return; 140 return;
145 141
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 } 324 }
329 ]); 325 ]);
330 collections.filterLists = new Collection( 326 collections.filterLists = new Collection(
331 [ 327 [
332 { 328 {
333 id: "all-filter-lists-table", 329 id: "all-filter-lists-table",
334 useOriginalTitle: true 330 useOriginalTitle: true
335 } 331 }
336 ]); 332 ]);
337 333
338 function updateLanguageCollections(subscription) 334 function toggleShowLanguage(subscription)
339 { 335 {
340 if (subscription.disabled) 336 if (subscription.recommended == "ads")
341 { 337 {
342 collections.allLangs.addItems(subscription); 338 if (subscription.disabled)
343 collections.langs.removeItem(subscription); 339 {
344 } 340 collections.allLangs.addItem(subscription);
345 else 341 collections.langs.removeItem(subscription);
346 { 342 }
347 collections.allLangs.removeItem(subscription); 343 else
348 collections.langs.addItems(subscription); 344 {
345 collections.allLangs.removeItem(subscription);
346 collections.langs.addItem(subscription);
347 }
349 } 348 }
350 } 349 }
351 350
352 function addSubscription(subscription) 351 function addSubscription(subscription)
353 { 352 {
354 var collection; 353 var collection;
355 if (subscription.recommended) 354 if (subscription.recommended)
356 { 355 {
357 if (subscription.recommended != "ads") 356 if (subscription.recommended != "ads")
358 collection = collections.popular; 357 collection = collections.popular;
359 else if (subscription.disabled == false) 358 else if (subscription.disabled == false)
360 collection = collections.langs; 359 collection = collections.langs;
361 else 360 else
362 collection = collections.allLangs; 361 collection = collections.allLangs;
363 } 362 }
364 else if (subscription.url == acceptableAdsUrl) 363 else if (subscription.url == acceptableAdsUrl)
365 collection = collections.acceptableAds; 364 collection = collections.acceptableAds;
366 else 365 else
367 collection = collections.custom; 366 collection = collections.custom;
368 367
369 collection.addItems(subscription); 368 collection.addItem(subscription);
370 subscriptionsMap[subscription.url] = subscription; 369 subscriptionsMap[subscription.url] = subscription;
370 toggleShowLanguage(subscription);
371 updateTooltips(); 371 updateTooltips();
372 } 372 }
373 373
374 function updateSubscription(subscription) 374 function updateSubscription(subscription)
375 { 375 {
376 for (var name in collections) 376 for (var name in collections)
377 collections[name].updateItem(subscription); 377 collections[name].updateItem(subscription);
378
379 toggleShowLanguage(subscription);
378 } 380 }
379 381
380 function updateFilter(filter) 382 function updateFilter(filter)
381 { 383 {
382 var match = filter.text.match(/^@@\|\|([^\/:]+)\^\$document$/); 384 var match = filter.text.match(/^@@\|\|([^\/:]+)\^\$document$/);
383 if (match && !filtersMap[filter.text]) 385 if (match && !filtersMap[filter.text])
384 { 386 {
385 filter.title = match[1]; 387 filter.title = match[1];
386 collections.whitelist.addItems(filter); 388 collections.whitelist.addItem(filter);
387 } 389 }
388 else 390 else
389 collections.customFilters.addItems(filter); 391 collections.customFilters.addItem(filter);
390 392
391 filtersMap[filter.text] = filter; 393 filtersMap[filter.text] = filter;
392 } 394 }
393 395
394 function loadRecommendations() 396 function loadRecommendations()
395 { 397 {
396 fetch("subscriptions.xml") 398 fetch("subscriptions.xml")
397 .then(function(response) 399 .then(function(response)
398 { 400 {
399 return response.text(); 401 return response.text();
400 }) 402 })
401 .then(function(text) 403 .then(function(text)
402 { 404 {
403 var list = document.getElementById("subscriptionSelector"); 405 var list = document.getElementById("subscriptionSelector");
404 var doc = new DOMParser().parseFromString(text, "application/xml"); 406 var doc = new DOMParser().parseFromString(text, "application/xml");
405 var elements = doc.documentElement.getElementsByTagName("subscription"); 407 var elements = doc.documentElement.getElementsByTagName("subscription");
406 for (var i = 0; i < elements.length; i++) 408 for (var i = 0; i < elements.length; i++)
407 { 409 {
408 var element = elements[i]; 410 var element = elements[i];
409 var type = element.getAttribute("type"); 411 var type = element.getAttribute("type");
410 var subscription = { 412 var subscription = {
411 disabled: null, 413 disabled: true,
412 downloadStatus: null, 414 downloadStatus: null,
413 homepage: null, 415 homepage: null,
414 originalTitle: element.getAttribute("title"), 416 originalTitle: element.getAttribute("title"),
415 recommended: type, 417 recommended: type,
416 url: element.getAttribute("url") 418 url: element.getAttribute("url")
417 }; 419 };
418 420
419 var prefix = element.getAttribute("prefixes"); 421 var prefix = element.getAttribute("prefixes");
420 if (prefix) 422 if (prefix)
421 { 423 {
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 if (property == "title" && knownSubscription.recommended) 1022 if (property == "title" && knownSubscription.recommended)
1021 knownSubscription.originalTitle = subscription.title; 1023 knownSubscription.originalTitle = subscription.title;
1022 else 1024 else
1023 knownSubscription[property] = subscription[property]; 1025 knownSubscription[property] = subscription[property];
1024 } 1026 }
1025 subscription = knownSubscription; 1027 subscription = knownSubscription;
1026 } 1028 }
1027 switch (action) 1029 switch (action)
1028 { 1030 {
1029 case "disabled": 1031 case "disabled":
1030 if (subscription.recommended == "ads")
1031 updateLanguageCollections(subscription);
1032 updateSubscription(subscription); 1032 updateSubscription(subscription);
1033 break; 1033 break;
1034 case "downloading": 1034 case "downloading":
1035 case "downloadStatus": 1035 case "downloadStatus":
1036 case "homepage": 1036 case "homepage":
1037 case "lastDownload": 1037 case "lastDownload":
1038 case "title": 1038 case "title":
1039 updateSubscription(subscription); 1039 updateSubscription(subscription);
1040 break; 1040 break;
1041 case "added": 1041 case "added":
1042 if (subscription.recommended == "ads") 1042 if (subscription.url in subscriptionsMap)
1043 updateLanguageCollections(subscription);
1044 else if (subscription.url in subscriptionsMap)
1045 updateSubscription(subscription); 1043 updateSubscription(subscription);
1046 else 1044 else
1047 addSubscription(subscription); 1045 addSubscription(subscription);
1048 1046
1049 collections.filterLists.addItems(subscription); 1047 collections.filterLists.addItem(subscription);
1050 break; 1048 break;
1051 case "removed": 1049 case "removed":
1052 if (subscription.url == acceptableAdsUrl || subscription.recommended) 1050 if (subscription.url == acceptableAdsUrl || subscription.recommended)
1053 { 1051 {
1054 subscription.disabled = true; 1052 subscription.disabled = true;
1055 onSubscriptionMessage("disabled", subscription); 1053 onSubscriptionMessage("disabled", subscription);
1056 } 1054 }
1057 else 1055 else
1058 { 1056 {
1059 collections.custom.removeItem(subscription); 1057 collections.custom.removeItem(subscription);
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 ext.backgroundPage.sendMessage( 1278 ext.backgroundPage.sendMessage(
1281 { 1279 {
1282 type: "subscriptions.listen", 1280 type: "subscriptions.listen",
1283 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1281 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1284 "title", "downloadStatus", "downloading"] 1282 "title", "downloadStatus", "downloading"]
1285 }); 1283 });
1286 1284
1287 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1285 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1288 window.addEventListener("hashchange", onHashChange, false); 1286 window.addEventListener("hashchange", onHashChange, false);
1289 })(); 1287 })();
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld