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: Created Sept. 25, 2017, 8:10 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)
ire 2017/09/26 08:37:55 NIT: This function and the nested if statements ar
saroyanm 2017/09/26 16:35:25 Absolutely, my bad, now should be more readable I
56 { 56 {
57 let placeholders = table.querySelectorAll(".empty-placeholder"); 57 if (removeEmpty)
58 {
59 let placeholders = table.querySelectorAll(".empty-placeholder");
60 if (placeholders.length > 0)
61 {
62 for (let placeholder of placeholders)
63 table.removeChild(placeholder);
64 }
58 65
59 if (texts && placeholders.length == 0) 66 if (detail.removeEmptyAction)
67 execAction(detail.removeEmptyAction, table);
68 }
69 else
60 { 70 {
61 for (let text of texts) 71 if (detail.emptyText)
62 { 72 {
63 let placeholder = document.createElement("li"); 73 for (let text of detail.emptyText)
64 placeholder.className = "empty-placeholder"; 74 {
65 placeholder.textContent = getMessage(text); 75 let placeholder = document.createElement("li");
66 table.appendChild(placeholder); 76 placeholder.className = "empty-placeholder";
77 placeholder.textContent = getMessage(text);
78 table.appendChild(placeholder);
79 }
67 } 80 }
68 } 81
69 else if (placeholders.length > 0) 82 if (detail.setEmptyAction)
70 { 83 execAction(detail.setEmptyAction, table);
71 for (let placeholder of placeholders)
72 table.removeChild(placeholder);
73 } 84 }
74 }; 85 };
75 86
76 Collection.prototype._createElementQuery = function(item) 87 Collection.prototype._createElementQuery = function(item)
77 { 88 {
78 let access = (item.url || item.text).replace(/'/g, "\\'"); 89 let access = (item.url || item.text).replace(/'/g, "\\'");
79 return function(container) 90 return function(container)
80 { 91 {
81 return container.querySelector("[data-access='" + access + "']"); 92 return container.querySelector("[data-access='" + access + "']");
82 }; 93 };
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 157
147 for (let control of listItem.querySelectorAll(".control")) 158 for (let control of listItem.querySelectorAll(".control"))
148 { 159 {
149 if (control.hasAttribute("title")) 160 if (control.hasAttribute("title"))
150 { 161 {
151 let titleValue = getMessage(control.getAttribute("title")); 162 let titleValue = getMessage(control.getAttribute("title"));
152 control.setAttribute("title", titleValue); 163 control.setAttribute("title", titleValue);
153 } 164 }
154 } 165 }
155 166
156 this._setEmpty(table, null); 167 this._setEmpty(table, detail, true);
157 if (table.children.length > 0) 168 if (table.children.length > 0)
158 table.insertBefore(listItem, table.children[this.items.indexOf(item)]); 169 table.insertBefore(listItem, table.children[this.items.indexOf(item)]);
159 else 170 else
160 table.appendChild(listItem); 171 table.appendChild(listItem);
161 172
162 this.updateItem(item); 173 this.updateItem(item);
163 } 174 }
164 return length; 175 return length;
165 }; 176 };
166 177
(...skipping 25 matching lines...) Expand all
192 break; 203 break;
193 204
194 focusableElement = focusableElement.parentElement; 205 focusableElement = focusableElement.parentElement;
195 } 206 }
196 focusNextElement(focusableElement || document, control); 207 focusNextElement(focusableElement || document, control);
197 } 208 }
198 } 209 }
199 210
200 element.parentElement.removeChild(element); 211 element.parentElement.removeChild(element);
201 if (this.items.length == 0) 212 if (this.items.length == 0)
202 this._setEmpty(table, detail.emptyText); 213 this._setEmpty(table, detail);
203 } 214 }
204 }; 215 };
205 216
206 Collection.prototype.updateItem = function(item) 217 Collection.prototype.updateItem = function(item)
207 { 218 {
208 let oldIndex = this.items.indexOf(item); 219 let oldIndex = this.items.indexOf(item);
209 this._sortItems(); 220 this._sortItems();
210 let access = (item.url || item.text).replace(/'/g, "\\'"); 221 let access = (item.url || item.text).replace(/'/g, "\\'");
211 for (let i = 0; i < this.details.length; i++) 222 for (let i = 0; i < this.details.length; i++)
212 { 223 {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 { 320 {
310 let table = E(detail.id); 321 let table = E(detail.id);
311 let element = table.firstChild; 322 let element = table.firstChild;
312 while (element) 323 while (element)
313 { 324 {
314 if (element.tagName == "LI" && !element.classList.contains("static")) 325 if (element.tagName == "LI" && !element.classList.contains("static"))
315 table.removeChild(element); 326 table.removeChild(element);
316 element = element.nextElementSibling; 327 element = element.nextElementSibling;
317 } 328 }
318 329
319 this._setEmpty(table, detail.emptyText); 330 this._setEmpty(table, detail);
320 } 331 }
321 }; 332 };
322 333
323 function focusNextElement(container, currentElement) 334 function focusNextElement(container, currentElement)
324 { 335 {
325 let focusables = container.querySelectorAll("a, button, input, .control"); 336 let focusables = container.querySelectorAll("a, button, input, .control");
326 focusables = Array.prototype.slice.call(focusables); 337 focusables = Array.prototype.slice.call(focusables);
327 let index = focusables.indexOf(currentElement); 338 let index = focusables.indexOf(currentElement);
328 index += (index == focusables.length - 1) ? -1 : 1; 339 index += (index == focusables.length - 1) ? -1 : 1;
329 340
(...skipping 17 matching lines...) Expand all
347 } 358 }
348 ]); 359 ]);
349 collections.allLangs = new Collection([ 360 collections.allLangs = new Collection([
350 { 361 {
351 id: "all-lang-table-add", 362 id: "all-lang-table-add",
352 emptyText: ["options_dialog_language_other_empty"] 363 emptyText: ["options_dialog_language_other_empty"]
353 } 364 }
354 ]); 365 ]);
355 collections.more = new Collection([ 366 collections.more = new Collection([
356 { 367 {
357 id: "more-list-table" 368 id: "more-list-table",
369 setEmptyAction: "hide-more-section",
370 removeEmptyAction: "show-more-section"
ire 2017/09/26 08:37:55 NIT: Calling it "hide-more-section" seems to gener
saroyanm 2017/09/26 16:35:25 I agree with you, done.
358 } 371 }
359 ]); 372 ]);
360 collections.whitelist = new Collection([ 373 collections.whitelist = new Collection([
361 { 374 {
362 id: "whitelisting-table", 375 id: "whitelisting-table",
363 emptyText: ["options_whitelist_empty_1", "options_whitelist_empty_2"] 376 emptyText: ["options_whitelist_empty_1", "options_whitelist_empty_2"]
364 } 377 }
365 ]); 378 ]);
366 collections.filterLists = new Collection([ 379 collections.filterLists = new Collection([
367 { 380 {
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 break; 589 break;
577 } 590 }
578 } 591 }
579 break; 592 break;
580 case "close-dialog": 593 case "close-dialog":
581 closeDialog(); 594 closeDialog();
582 break; 595 break;
583 case "edit-custom-filters": 596 case "edit-custom-filters":
584 setCustomFiltersView("write"); 597 setCustomFiltersView("write");
585 break; 598 break;
599 case "hide-more-section":
600 E("more-filters").setAttribute("aria-hidden", true);
601 break;
586 case "hide-notification": 602 case "hide-notification":
587 hideNotification(); 603 hideNotification();
588 break; 604 break;
589 case "import-subscription": { 605 case "import-subscription": {
590 let url = E("blockingList-textbox").value; 606 let url = E("blockingList-textbox").value;
591 addEnableSubscription(url); 607 addEnableSubscription(url);
592 closeDialog(); 608 closeDialog();
593 break; 609 break;
594 } 610 }
595 case "open-context-menu": { 611 case "open-context-menu": {
(...skipping 23 matching lines...) Expand all
619 sendMessageHandleErrors({ 635 sendMessageHandleErrors({
620 type: "filters.importRaw", 636 type: "filters.importRaw",
621 text: E("custom-filters-raw").value, 637 text: E("custom-filters-raw").value,
622 removeExisting: true 638 removeExisting: true
623 }, 639 },
624 () => 640 () =>
625 { 641 {
626 setCustomFiltersView("read"); 642 setCustomFiltersView("read");
627 }); 643 });
628 break; 644 break;
645 case "show-more-section":
646 E("more-filters").setAttribute("aria-hidden", false);
647 break;
629 case "switch-acceptable-ads": 648 case "switch-acceptable-ads":
630 let value = element.value || element.dataset.value; 649 let value = element.value || element.dataset.value;
631 ext.backgroundPage.sendMessage({ 650 ext.backgroundPage.sendMessage({
632 type: value == "privacy" ? "subscriptions.add" : 651 type: value == "privacy" ? "subscriptions.add" :
633 "subscriptions.remove", 652 "subscriptions.remove",
634 url: acceptableAdsPrivacyUrl 653 url: acceptableAdsPrivacyUrl
635 }); 654 });
636 ext.backgroundPage.sendMessage({ 655 ext.backgroundPage.sendMessage({
637 type: value == "ads" ? "subscriptions.add" : "subscriptions.remove", 656 type: value == "ads" ? "subscriptions.add" : "subscriptions.remove",
638 url: acceptableAdsUrl 657 url: acceptableAdsUrl
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 }); 1396 });
1378 ext.backgroundPage.sendMessage({ 1397 ext.backgroundPage.sendMessage({
1379 type: "subscriptions.listen", 1398 type: "subscriptions.listen",
1380 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1399 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1381 "title", "downloadStatus", "downloading"] 1400 "title", "downloadStatus", "downloading"]
1382 }); 1401 });
1383 1402
1384 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1403 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1385 window.addEventListener("hashchange", onHashChange, false); 1404 window.addEventListener("hashchange", onHashChange, false);
1386 } 1405 }
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