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: Restricted duplications Created Aug. 1, 2016, 6:14 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)
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 itemsToAdd = []; 75 if (this.items.indexOf(item) >= 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)
81 return; 76 return;
82 77
83 Array.prototype.push.apply(this.items, itemsToAdd); 78 this.items.push(item);
84 this.items.sort(function(a, b) 79 this.items.sort(function(a, b)
85 { 80 {
86 // 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
87 // 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
88 // 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
89 // of the filter lists in the Advanced tab. 84 // of the filter lists in the Advanced tab.
90 if (a.url == acceptableAdsUrl) 85 if (a.url == acceptableAdsUrl)
91 return 1; 86 return 1;
92 if (b.url == acceptableAdsUrl) 87 if (b.url == acceptableAdsUrl)
93 return -1; 88 return -1;
94 89
95 var aTitle = this._getItemTitle(a, 0).toLowerCase(); 90 var aTitle = this._getItemTitle(a, 0).toLowerCase();
96 var bTitle = this._getItemTitle(b, 0).toLowerCase(); 91 var bTitle = this._getItemTitle(b, 0).toLowerCase();
97 return aTitle.localeCompare(bTitle); 92 return aTitle.localeCompare(bTitle);
98 }.bind(this)); 93 }.bind(this));
99 94
100 for (var j = 0; j < this.details.length; j++) 95 for (var j = 0; j < this.details.length; j++)
101 { 96 {
102 var table = E(this.details[j].id); 97 var table = E(this.details[j].id);
103 var template = table.querySelector("template"); 98 var template = table.querySelector("template");
104 for (var i = 0; i < itemsToAdd.length; i++) 99 var listItem = document.createElement("li");
105 { 100 listItem.appendChild(document.importNode(template.content, true));
106 var item = itemsToAdd[i]; 101 listItem.setAttribute("aria-label", this._getItemTitle(item, j));
107 var listItem = document.createElement("li"); 102 listItem.setAttribute("data-access", item.url || item.text);
108 listItem.appendChild(document.importNode(template.content, true)); 103 listItem.setAttribute("role", "section");
109 listItem.setAttribute("aria-label", this._getItemTitle(item, j)); 104
110 listItem.setAttribute("data-access", item.url || item.text); 105 var label = listItem.querySelector(".display");
111 listItem.setAttribute("role", "section"); 106 if (item.recommended && label.hasAttribute("data-tooltip"))
112 107 {
113 var label = listItem.querySelector(".display"); 108 var tooltipId = label.getAttribute("data-tooltip");
114 if (item.recommended && label.hasAttribute("data-tooltip")) 109 tooltipId = tooltipId.replace("%value%", item.recommended);
115 { 110 label.setAttribute("data-tooltip", tooltipId);
116 var tooltipId = label.getAttribute("data-tooltip"); 111 }
117 tooltipId = tooltipId.replace("%value%", item.recommended); 112
118 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)
119 } 120 }
120 121 }
121 var controls = listItem.querySelectorAll(".control"); 122
122 for (var k = 0; k < controls.length; k++) 123 this._setEmpty(table, null);
123 { 124 if (table.hasChildNodes())
124 if (controls[k].hasAttribute("title")) 125 {
125 { 126 table.insertBefore(listItem,
126 var titleValue = getMessage(controls[k].getAttribute("title")); 127 table.childNodes[this.items.indexOf(item)]);
127 controls[k].setAttribute("title", titleValue) 128 }
128 } 129 else
129 } 130 table.appendChild(listItem);
130 131 this.updateItem(item);
131 this._setEmpty(table, null);
132 if (table.hasChildNodes())
133 {
134 table.insertBefore(listItem,
135 table.childNodes[this.items.indexOf(item)]);
136 }
137 else
138 table.appendChild(listItem);
139 this.updateItem(item);
140 }
141 } 132 }
142 return length; 133 return length;
143 }; 134 };
144 135
145 Collection.prototype.removeItem = function(item) 136 Collection.prototype.removeItem = function(item)
146 { 137 {
147 var index = this.items.indexOf(item); 138 var index = this.items.indexOf(item);
148 if (index == -1) 139 if (index == -1)
149 return; 140 return;
150 141
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 { 328 {
338 id: "all-filter-lists-table", 329 id: "all-filter-lists-table",
339 useOriginalTitle: true 330 useOriginalTitle: true
340 } 331 }
341 ]); 332 ]);
342 333
343 function toggleShowLanguage(subscription) 334 function toggleShowLanguage(subscription)
344 { 335 {
345 if (subscription.recommended == "ads") 336 if (subscription.recommended == "ads")
346 { 337 {
347 if (subscription.disabled == false) 338 if (subscription.disabled)
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
339 {
340 collections.allLangs.addItem(subscription);
341 collections.langs.removeItem(subscription);
342 }
343 else
348 { 344 {
349 collections.allLangs.removeItem(subscription); 345 collections.allLangs.removeItem(subscription);
350 collections.langs.addItems(subscription); 346 collections.langs.addItem(subscription);
351 }
352 else
353 {
354 collections.allLangs.addItems(subscription);
355 collections.langs.removeItem(subscription);
356 } 347 }
357 } 348 }
358 } 349 }
359 350
360 function addSubscription(subscription) 351 function addSubscription(subscription)
361 { 352 {
362 var collection; 353 var collection;
363 if (subscription.recommended) 354 if (subscription.recommended)
364 { 355 {
365 if (subscription.recommended != "ads") 356 if (subscription.recommended != "ads")
366 collection = collections.popular; 357 collection = collections.popular;
367 else if (subscription.disabled == false) 358 else if (subscription.disabled == false)
368 collection = collections.langs; 359 collection = collections.langs;
369 else 360 else
370 collection = collections.allLangs; 361 collection = collections.allLangs;
371 } 362 }
372 else if (subscription.url == acceptableAdsUrl) 363 else if (subscription.url == acceptableAdsUrl)
373 collection = collections.acceptableAds; 364 collection = collections.acceptableAds;
374 else 365 else
375 collection = collections.custom; 366 collection = collections.custom;
376 367
377 collection.addItems(subscription); 368 collection.addItem(subscription);
378 subscriptionsMap[subscription.url] = subscription; 369 subscriptionsMap[subscription.url] = subscription;
379 toggleShowLanguage(subscription); 370 toggleShowLanguage(subscription);
380 updateTooltips(); 371 updateTooltips();
381 } 372 }
382 373
383 function updateSubscription(subscription) 374 function updateSubscription(subscription)
384 { 375 {
385 for (var name in collections) 376 for (var name in collections)
386 collections[name].updateItem(subscription); 377 collections[name].updateItem(subscription);
387 378
388 toggleShowLanguage(subscription); 379 toggleShowLanguage(subscription);
389 } 380 }
390 381
391 function updateFilter(filter) 382 function updateFilter(filter)
392 { 383 {
393 var match = filter.text.match(/^@@\|\|([^\/:]+)\^\$document$/); 384 var match = filter.text.match(/^@@\|\|([^\/:]+)\^\$document$/);
394 if (match && !filtersMap[filter.text]) 385 if (match && !filtersMap[filter.text])
395 { 386 {
396 filter.title = match[1]; 387 filter.title = match[1];
397 collections.whitelist.addItems(filter); 388 collections.whitelist.addItem(filter);
398 } 389 }
399 else 390 else
400 collections.customFilters.addItems(filter); 391 collections.customFilters.addItem(filter);
401 392
402 filtersMap[filter.text] = filter; 393 filtersMap[filter.text] = filter;
403 } 394 }
404 395
405 function loadRecommendations() 396 function loadRecommendations()
406 { 397 {
407 fetch("subscriptions.xml") 398 fetch("subscriptions.xml")
408 .then(function(response) 399 .then(function(response)
409 { 400 {
410 return response.text(); 401 return response.text();
411 }) 402 })
412 .then(function(text) 403 .then(function(text)
413 { 404 {
414 var list = document.getElementById("subscriptionSelector"); 405 var list = document.getElementById("subscriptionSelector");
415 var doc = new DOMParser().parseFromString(text, "application/xml"); 406 var doc = new DOMParser().parseFromString(text, "application/xml");
416 var elements = doc.documentElement.getElementsByTagName("subscription"); 407 var elements = doc.documentElement.getElementsByTagName("subscription");
417 for (var i = 0; i < elements.length; i++) 408 for (var i = 0; i < elements.length; i++)
418 { 409 {
419 var element = elements[i]; 410 var element = elements[i];
420 var type = element.getAttribute("type"); 411 var type = element.getAttribute("type");
421 var subscription = { 412 var subscription = {
422 disabled: null, 413 disabled: true,
423 downloadStatus: null, 414 downloadStatus: null,
424 homepage: null, 415 homepage: null,
425 originalTitle: element.getAttribute("title"), 416 originalTitle: element.getAttribute("title"),
426 recommended: type, 417 recommended: type,
427 url: element.getAttribute("url") 418 url: element.getAttribute("url")
428 }; 419 };
429 420
430 var prefix = element.getAttribute("prefixes"); 421 var prefix = element.getAttribute("prefixes");
431 if (prefix) 422 if (prefix)
432 { 423 {
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 case "lastDownload": 1037 case "lastDownload":
1047 case "title": 1038 case "title":
1048 updateSubscription(subscription); 1039 updateSubscription(subscription);
1049 break; 1040 break;
1050 case "added": 1041 case "added":
1051 if (subscription.url in subscriptionsMap) 1042 if (subscription.url in subscriptionsMap)
1052 updateSubscription(subscription); 1043 updateSubscription(subscription);
1053 else 1044 else
1054 addSubscription(subscription); 1045 addSubscription(subscription);
1055 1046
1056 collections.filterLists.addItems(subscription); 1047 collections.filterLists.addItem(subscription);
1057 break; 1048 break;
1058 case "removed": 1049 case "removed":
1059 if (subscription.url == acceptableAdsUrl || subscription.recommended) 1050 if (subscription.url == acceptableAdsUrl || subscription.recommended)
1060 { 1051 {
1061 subscription.disabled = true; 1052 subscription.disabled = true;
1062 onSubscriptionMessage("disabled", subscription); 1053 onSubscriptionMessage("disabled", subscription);
1063 } 1054 }
1064 else 1055 else
1065 { 1056 {
1066 collections.custom.removeItem(subscription); 1057 collections.custom.removeItem(subscription);
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 ext.backgroundPage.sendMessage( 1278 ext.backgroundPage.sendMessage(
1288 { 1279 {
1289 type: "subscriptions.listen", 1280 type: "subscriptions.listen",
1290 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1281 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1291 "title", "downloadStatus", "downloading"] 1282 "title", "downloadStatus", "downloading"]
1292 }); 1283 });
1293 1284
1294 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1285 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1295 window.addEventListener("hashchange", onHashChange, false); 1286 window.addEventListener("hashchange", onHashChange, false);
1296 })(); 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