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

Side by Side Diff: new-options.js

Issue 29555849: Issue 5778 - Hide More filters section when there is no filter (Closed)
Patch Set: Fixed nits Created Sept. 26, 2017, 4:33 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 | « new-options.html ('k') | 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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 const minuteInMs = 60000; 45 const minuteInMs = 60000;
46 const hourInMs = 3600000; 46 const hourInMs = 3600000;
47 const fullDayInMs = 86400000; 47 const fullDayInMs = 86400000;
48 48
49 function Collection(details) 49 function Collection(details)
50 { 50 {
51 this.details = details; 51 this.details = details;
52 this.items = []; 52 this.items = [];
53 } 53 }
54 54
55 Collection.prototype._setEmpty = function(table, texts) 55 Collection.prototype._setEmpty = function(table, detail, removeEmpty)
56 { 56 {
57 let placeholders = table.querySelectorAll(".empty-placeholder"); 57 if (removeEmpty)
58 {
59 let placeholders = table.querySelectorAll(".empty-placeholder");
60 for (let placeholder of placeholders)
61 table.removeChild(placeholder);
58 62
59 if (texts && placeholders.length == 0) 63 execAction(detail.removeEmptyAction, table);
64 }
65 else
60 { 66 {
61 for (let text of texts) 67 let {emptyTexts = []} = detail;
68 for (let text of emptyTexts)
62 { 69 {
63 let placeholder = document.createElement("li"); 70 let placeholder = document.createElement("li");
64 placeholder.className = "empty-placeholder"; 71 placeholder.className = "empty-placeholder";
65 placeholder.textContent = getMessage(text); 72 placeholder.textContent = getMessage(text);
66 table.appendChild(placeholder); 73 table.appendChild(placeholder);
67 } 74 }
68 } 75
69 else if (placeholders.length > 0) 76 execAction(detail.setEmptyAction, table);
70 {
71 for (let placeholder of placeholders)
72 table.removeChild(placeholder);
73 } 77 }
74 }; 78 };
75 79
76 Collection.prototype._createElementQuery = function(item) 80 Collection.prototype._createElementQuery = function(item)
77 { 81 {
78 let access = (item.url || item.text).replace(/'/g, "\\'"); 82 let access = (item.url || item.text).replace(/'/g, "\\'");
79 return function(container) 83 return function(container)
80 { 84 {
81 return container.querySelector("[data-access='" + access + "']"); 85 return container.querySelector("[data-access='" + access + "']");
82 }; 86 };
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 150
147 for (let control of listItem.querySelectorAll(".control")) 151 for (let control of listItem.querySelectorAll(".control"))
148 { 152 {
149 if (control.hasAttribute("title")) 153 if (control.hasAttribute("title"))
150 { 154 {
151 let titleValue = getMessage(control.getAttribute("title")); 155 let titleValue = getMessage(control.getAttribute("title"));
152 control.setAttribute("title", titleValue); 156 control.setAttribute("title", titleValue);
153 } 157 }
154 } 158 }
155 159
156 this._setEmpty(table, null); 160 this._setEmpty(table, detail, true);
157 if (table.children.length > 0) 161 if (table.children.length > 0)
158 table.insertBefore(listItem, table.children[this.items.indexOf(item)]); 162 table.insertBefore(listItem, table.children[this.items.indexOf(item)]);
159 else 163 else
160 table.appendChild(listItem); 164 table.appendChild(listItem);
161 165
162 this.updateItem(item); 166 this.updateItem(item);
163 } 167 }
164 return length; 168 return length;
165 }; 169 };
166 170
(...skipping 25 matching lines...) Expand all
192 break; 196 break;
193 197
194 focusableElement = focusableElement.parentElement; 198 focusableElement = focusableElement.parentElement;
195 } 199 }
196 focusNextElement(focusableElement || document, control); 200 focusNextElement(focusableElement || document, control);
197 } 201 }
198 } 202 }
199 203
200 element.parentElement.removeChild(element); 204 element.parentElement.removeChild(element);
201 if (this.items.length == 0) 205 if (this.items.length == 0)
202 this._setEmpty(table, detail.emptyText); 206 this._setEmpty(table, detail);
203 } 207 }
204 }; 208 };
205 209
206 Collection.prototype.updateItem = function(item) 210 Collection.prototype.updateItem = function(item)
207 { 211 {
208 let oldIndex = this.items.indexOf(item); 212 let oldIndex = this.items.indexOf(item);
209 this._sortItems(); 213 this._sortItems();
210 let access = (item.url || item.text).replace(/'/g, "\\'"); 214 let access = (item.url || item.text).replace(/'/g, "\\'");
211 for (let i = 0; i < this.details.length; i++) 215 for (let i = 0; i < this.details.length; i++)
212 { 216 {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 { 313 {
310 let table = E(detail.id); 314 let table = E(detail.id);
311 let element = table.firstChild; 315 let element = table.firstChild;
312 while (element) 316 while (element)
313 { 317 {
314 if (element.tagName == "LI" && !element.classList.contains("static")) 318 if (element.tagName == "LI" && !element.classList.contains("static"))
315 table.removeChild(element); 319 table.removeChild(element);
316 element = element.nextElementSibling; 320 element = element.nextElementSibling;
317 } 321 }
318 322
319 this._setEmpty(table, detail.emptyText); 323 this._setEmpty(table, detail);
320 } 324 }
321 }; 325 };
322 326
323 function focusNextElement(container, currentElement) 327 function focusNextElement(container, currentElement)
324 { 328 {
325 let focusables = container.querySelectorAll("a, button, input, .control"); 329 let focusables = container.querySelectorAll("a, button, input, .control");
326 focusables = Array.prototype.slice.call(focusables); 330 focusables = Array.prototype.slice.call(focusables);
327 let index = focusables.indexOf(currentElement); 331 let index = focusables.indexOf(currentElement);
328 index += (index == focusables.length - 1) ? -1 : 1; 332 index += (index == focusables.length - 1) ? -1 : 1;
329 333
330 let nextElement = focusables[index]; 334 let nextElement = focusables[index];
331 if (!nextElement) 335 if (!nextElement)
332 return false; 336 return false;
333 337
334 nextElement.focus(); 338 nextElement.focus();
335 return true; 339 return true;
336 } 340 }
337 341
338 collections.protection = new Collection([ 342 collections.protection = new Collection([
339 { 343 {
340 id: "recommend-protection-list-table" 344 id: "recommend-protection-list-table"
341 } 345 }
342 ]); 346 ]);
343 collections.langs = new Collection([ 347 collections.langs = new Collection([
344 { 348 {
345 id: "blocking-languages-table", 349 id: "blocking-languages-table",
346 emptyText: ["options_language_empty"] 350 emptyTexts: ["options_language_empty"]
347 } 351 }
348 ]); 352 ]);
349 collections.allLangs = new Collection([ 353 collections.allLangs = new Collection([
350 { 354 {
351 id: "all-lang-table-add", 355 id: "all-lang-table-add",
352 emptyText: ["options_dialog_language_other_empty"] 356 emptyTexts: ["options_dialog_language_other_empty"]
353 } 357 }
354 ]); 358 ]);
355 collections.more = new Collection([ 359 collections.more = new Collection([
356 { 360 {
357 id: "more-list-table" 361 id: "more-list-table",
362 setEmptyAction: "hide-more-filters-section",
363 removeEmptyAction: "show-more-filters-section"
358 } 364 }
359 ]); 365 ]);
360 collections.whitelist = new Collection([ 366 collections.whitelist = new Collection([
361 { 367 {
362 id: "whitelisting-table", 368 id: "whitelisting-table",
363 emptyText: ["options_whitelist_empty_1", "options_whitelist_empty_2"] 369 emptyTexts: ["options_whitelist_empty_1", "options_whitelist_empty_2"]
364 } 370 }
365 ]); 371 ]);
366 collections.filterLists = new Collection([ 372 collections.filterLists = new Collection([
367 { 373 {
368 id: "all-filter-lists-table", 374 id: "all-filter-lists-table",
369 useOriginalTitle: true 375 useOriginalTitle: true
370 } 376 }
371 ]); 377 ]);
372 378
373 function addSubscription(subscription) 379 function addSubscription(subscription)
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 break; 582 break;
577 } 583 }
578 } 584 }
579 break; 585 break;
580 case "close-dialog": 586 case "close-dialog":
581 closeDialog(); 587 closeDialog();
582 break; 588 break;
583 case "edit-custom-filters": 589 case "edit-custom-filters":
584 setCustomFiltersView("write"); 590 setCustomFiltersView("write");
585 break; 591 break;
592 case "hide-more-filters-section":
593 E("more-filters").setAttribute("aria-hidden", true);
594 break;
586 case "hide-notification": 595 case "hide-notification":
587 hideNotification(); 596 hideNotification();
588 break; 597 break;
589 case "import-subscription": { 598 case "import-subscription": {
590 let url = E("blockingList-textbox").value; 599 let url = E("blockingList-textbox").value;
591 addEnableSubscription(url); 600 addEnableSubscription(url);
592 closeDialog(); 601 closeDialog();
593 break; 602 break;
594 } 603 }
595 case "open-context-menu": { 604 case "open-context-menu": {
(...skipping 23 matching lines...) Expand all
619 sendMessageHandleErrors({ 628 sendMessageHandleErrors({
620 type: "filters.importRaw", 629 type: "filters.importRaw",
621 text: E("custom-filters-raw").value, 630 text: E("custom-filters-raw").value,
622 removeExisting: true 631 removeExisting: true
623 }, 632 },
624 () => 633 () =>
625 { 634 {
626 setCustomFiltersView("read"); 635 setCustomFiltersView("read");
627 }); 636 });
628 break; 637 break;
638 case "show-more-filters-section":
639 E("more-filters").setAttribute("aria-hidden", false);
640 break;
629 case "switch-acceptable-ads": 641 case "switch-acceptable-ads":
630 let value = element.value || element.dataset.value; 642 let value = element.value || element.dataset.value;
631 ext.backgroundPage.sendMessage({ 643 ext.backgroundPage.sendMessage({
632 type: value == "privacy" ? "subscriptions.add" : 644 type: value == "privacy" ? "subscriptions.add" :
633 "subscriptions.remove", 645 "subscriptions.remove",
634 url: acceptableAdsPrivacyUrl 646 url: acceptableAdsPrivacyUrl
635 }); 647 });
636 ext.backgroundPage.sendMessage({ 648 ext.backgroundPage.sendMessage({
637 type: value == "ads" ? "subscriptions.add" : "subscriptions.remove", 649 type: value == "ads" ? "subscriptions.add" : "subscriptions.remove",
638 url: acceptableAdsUrl 650 url: acceptableAdsUrl
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
1381 }); 1393 });
1382 ext.backgroundPage.sendMessage({ 1394 ext.backgroundPage.sendMessage({
1383 type: "subscriptions.listen", 1395 type: "subscriptions.listen",
1384 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1396 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1385 "title", "downloadStatus", "downloading"] 1397 "title", "downloadStatus", "downloading"]
1386 }); 1398 });
1387 1399
1388 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1400 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1389 window.addEventListener("hashchange", onHashChange, false); 1401 window.addEventListener("hashchange", onHashChange, false);
1390 } 1402 }
OLDNEW
« no previous file with comments | « new-options.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld