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

Side by Side Diff: new-options.js

Issue 29411555: Issue 5169 - Add whitelisted tab to the new options page (Closed)
Patch Set: Addressed Thomas comments Created May 16, 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
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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 25 matching lines...) Expand all
36 ["synchronize_checksum_mismatch", 36 ["synchronize_checksum_mismatch",
37 "options_filterList_lastDownload_checksumMismatch"] 37 "options_filterList_lastDownload_checksumMismatch"]
38 ]); 38 ]);
39 39
40 function Collection(details) 40 function Collection(details)
41 { 41 {
42 this.details = details; 42 this.details = details;
43 this.items = []; 43 this.items = [];
44 } 44 }
45 45
46 Collection.prototype._setEmpty = function(table, text) 46 Collection.prototype._setEmpty = function(table, texts)
47 { 47 {
48 let placeholder = table.querySelector(".empty-placeholder"); 48 let placeholders = table.querySelectorAll(".empty-placeholder");
49 if (text && !placeholder) 49
50 if (texts && placeholders.length == 0)
50 { 51 {
51 placeholder = document.createElement("li"); 52 for (let text of texts)
52 placeholder.className = "empty-placeholder"; 53 {
53 placeholder.textContent = getMessage(text); 54 let placeholder = document.createElement("li");
54 table.appendChild(placeholder); 55 placeholder.className = "empty-placeholder";
56 placeholder.textContent = getMessage(text);
57 table.appendChild(placeholder);
58 }
55 } 59 }
56 else if (placeholder) 60 else if (placeholders.length > 0)
57 table.removeChild(placeholder); 61 {
62 for (let placeholder of placeholders)
63 table.removeChild(placeholder);
64 }
58 }; 65 };
59 66
60 Collection.prototype._createElementQuery = function(item) 67 Collection.prototype._createElementQuery = function(item)
61 { 68 {
62 let access = (item.url || item.text).replace(/'/g, "\\'"); 69 let access = (item.url || item.text).replace(/'/g, "\\'");
63 return function(container) 70 return function(container)
64 { 71 {
65 return container.querySelector("[data-access='" + access + "']"); 72 return container.querySelector("[data-access='" + access + "']");
66 }; 73 };
67 }; 74 };
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 let title = this._getItemTitle(item, i); 196 let title = this._getItemTitle(item, i);
190 element.querySelector(".display").textContent = title; 197 element.querySelector(".display").textContent = title;
191 element.setAttribute("aria-label", title); 198 element.setAttribute("aria-label", title);
192 if (this.details[i].searchable) 199 if (this.details[i].searchable)
193 element.setAttribute("data-search", title.toLowerCase()); 200 element.setAttribute("data-search", title.toLowerCase());
194 let control = element.querySelector(".control[role='checkbox']"); 201 let control = element.querySelector(".control[role='checkbox']");
195 if (control) 202 if (control)
196 { 203 {
197 control.setAttribute("aria-checked", item.disabled == false); 204 control.setAttribute("aria-checked", item.disabled == false);
198 if (item.url == acceptableAdsUrl && this == collections.filterLists) 205 if (item.url == acceptableAdsUrl && this == collections.filterLists)
199 control.setAttribute("disabled", true); 206 control.setAttribute("disabled", true);
saroyanm 2017/05/18 16:21:52 Use disabled property for assigning disabled in cu
saroyanm 2017/05/22 09:38:24 Done.
200 } 207 }
201 208
202 let dateElement = element.querySelector(".date"); 209 let dateElement = element.querySelector(".date");
203 let timeElement = element.querySelector(".time"); 210 let timeElement = element.querySelector(".time");
204 if (dateElement && timeElement) 211 if (dateElement && timeElement)
205 { 212 {
206 let message = element.querySelector(".message"); 213 let message = element.querySelector(".message");
207 if (item.isDownloading) 214 if (item.isDownloading)
208 { 215 {
209 let text = getMessage("options_filterList_lastDownload_inProgress"); 216 let text = getMessage("options_filterList_lastDownload_inProgress");
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 } 284 }
278 285
279 collections.popular = new Collection([ 286 collections.popular = new Collection([
280 { 287 {
281 id: "recommend-list-table" 288 id: "recommend-list-table"
282 } 289 }
283 ]); 290 ]);
284 collections.langs = new Collection([ 291 collections.langs = new Collection([
285 { 292 {
286 id: "blocking-languages-table", 293 id: "blocking-languages-table",
287 emptyText: "options_dialog_language_added_empty" 294 emptyText: ["options_dialog_language_added_empty"]
288 }, 295 },
289 { 296 {
290 id: "blocking-languages-dialog-table", 297 id: "blocking-languages-dialog-table",
291 emptyText: "options_dialog_language_added_empty" 298 emptyText: ["options_dialog_language_added_empty"]
292 } 299 }
293 ]); 300 ]);
294 collections.allLangs = new Collection([ 301 collections.allLangs = new Collection([
295 { 302 {
296 id: "all-lang-table", 303 id: "all-lang-table",
297 emptyText: "options_dialog_language_other_empty", 304 emptyText: ["options_dialog_language_other_empty"],
298 searchable: true 305 searchable: true
299 } 306 }
300 ]); 307 ]);
301 collections.acceptableAds = new Collection([ 308 collections.acceptableAds = new Collection([
302 { 309 {
303 id: "acceptableads-table" 310 id: "acceptableads-table"
304 } 311 }
305 ]); 312 ]);
306 collections.custom = new Collection([ 313 collections.custom = new Collection([
307 { 314 {
308 id: "custom-list-table" 315 id: "custom-list-table"
309 } 316 }
310 ]); 317 ]);
311 collections.whitelist = new Collection([ 318 collections.whitelist = new Collection([
312 { 319 {
313 id: "whitelisting-table", 320 id: "whitelisting-table",
314 emptyText: "options_whitelisted_empty" 321 emptyText: ["options_whitelist_empty_1", "options_whitelist_empty_2"]
315 } 322 }
316 ]); 323 ]);
317 collections.customFilters = new Collection([ 324 collections.customFilters = new Collection([
318 { 325 {
319 id: "custom-filters-table", 326 id: "custom-filters-table",
320 emptyText: "options_customFilters_empty" 327 emptyText: ["options_customFilters_empty"]
321 } 328 }
322 ]); 329 ]);
323 collections.filterLists = new Collection([ 330 collections.filterLists = new Collection([
324 { 331 {
325 id: "all-filter-lists-table", 332 id: "all-filter-lists-table",
326 useOriginalTitle: true 333 useOriginalTitle: true
327 } 334 }
328 ]); 335 ]);
329 336
330 function toggleShowLanguage(subscription) 337 function toggleShowLanguage(subscription)
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 let dialog = E("dialog-content-predefined"); 502 let dialog = E("dialog-content-predefined");
496 let title = dialog.querySelector("h3").textContent; 503 let title = dialog.querySelector("h3").textContent;
497 let url = dialog.querySelector(".url").textContent; 504 let url = dialog.querySelector(".url").textContent;
498 addEnableSubscription(url, title); 505 addEnableSubscription(url, title);
499 closeDialog(); 506 closeDialog();
500 break; 507 break;
501 } 508 }
502 case "cancel-custom-filters": 509 case "cancel-custom-filters":
503 E("custom-filters").classList.remove("mode-edit"); 510 E("custom-filters").classList.remove("mode-edit");
504 break; 511 break;
505 case "cancel-domain-exception":
506 E("whitelisting-textbox").value = "";
507 document.querySelector("#whitelisting .controls").classList
508 .remove("mode-edit");
509 break;
510 case "close-dialog": 512 case "close-dialog":
511 closeDialog(); 513 closeDialog();
512 break; 514 break;
513 case "edit-custom-filters": 515 case "edit-custom-filters":
514 E("custom-filters").classList.add("mode-edit"); 516 E("custom-filters").classList.add("mode-edit");
515 editCustomFilters(); 517 editCustomFilters();
516 break; 518 break;
517 case "edit-domain-exception":
518 document.querySelector("#whitelisting .controls").classList
519 .add("mode-edit");
520 E("whitelisting-textbox").focus();
521 break;
522 case "import-subscription": { 519 case "import-subscription": {
523 let url = E("blockingList-textbox").value; 520 let url = E("blockingList-textbox").value;
524 addEnableSubscription(url); 521 addEnableSubscription(url);
525 closeDialog(); 522 closeDialog();
526 break; 523 break;
527 } 524 }
528 case "open-dialog": { 525 case "open-dialog": {
529 let dialog = findParentData(element, "dialog", false); 526 let dialog = findParentData(element, "dialog", false);
530 openDialog(dialog); 527 openDialog(dialog);
531 break; 528 break;
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 757
761 updateShareLink(); 758 updateShareLink();
762 updateTooltips(); 759 updateTooltips();
763 760
764 // Initialize interactive UI elements 761 // Initialize interactive UI elements
765 document.body.addEventListener("click", onClick, false); 762 document.body.addEventListener("click", onClick, false);
766 document.body.addEventListener("keyup", onKeyUp, false); 763 document.body.addEventListener("keyup", onKeyUp, false);
767 let placeholderValue = getMessage("options_dialog_language_find"); 764 let placeholderValue = getMessage("options_dialog_language_find");
768 E("find-language").setAttribute("placeholder", placeholderValue); 765 E("find-language").setAttribute("placeholder", placeholderValue);
769 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); 766 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false);
770 E("whitelisting-textbox").addEventListener("keypress", (e) => 767 let exampleValue = getMessage("options_whitelist_placeholder_example");
768 E("whitelisting-textbox").setAttribute("placeholder", exampleValue);
769 E("whitelisting-textbox").addEventListener("keyup", (e) =>
771 { 770 {
771 let addWhitelistButton = E("whitelisting-add-button");
772 addWhitelistButton.disabled = false;
772 if (getKey(e) == "Enter") 773 if (getKey(e) == "Enter")
773 addWhitelistedDomain(); 774 {
775 if (!addWhitelistButton.disabled)
776 addWhitelistedDomain();
777 }
778 else
779 {
780 for (let whitelistItem of collections.whitelist.items)
781 {
782 if (!e.target.value)
783 {
784 addWhitelistButton.disabled = true;
785 }
786 if (whitelistItem.title == e.target.value)
787 {
788 addWhitelistButton.disabled = true;
789 E("whitelisting-validation").textContent =
saroyanm 2017/05/16 20:20:07 I keep this solution here for now, adding the item
saroyanm 2017/05/18 16:21:52 Every new item needs to be added on top of the "co
saroyanm 2017/05/22 09:38:24 Done.
790 getMessage("options_whitelist_duplicate");
791 }
792 }
793 }
774 }, false); 794 }, false);
775 795
776 // Advanced tab 796 // Advanced tab
777 let tweaks = document.querySelectorAll("#tweaks li[data-pref]"); 797 let tweaks = document.querySelectorAll("#tweaks li[data-pref]");
778 tweaks = Array.prototype.map.call(tweaks, (checkbox) => 798 tweaks = Array.prototype.map.call(tweaks, (checkbox) =>
779 { 799 {
780 return checkbox.getAttribute("data-pref"); 800 return checkbox.getAttribute("data-pref");
781 }); 801 });
782 for (let key of tweaks) 802 for (let key of tweaks)
783 { 803 {
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 let domain = E("whitelisting-textbox"); 999 let domain = E("whitelisting-textbox");
980 if (domain.value) 1000 if (domain.value)
981 { 1001 {
982 sendMessageHandleErrors({ 1002 sendMessageHandleErrors({
983 type: "filters.add", 1003 type: "filters.add",
984 text: "@@||" + domain.value.toLowerCase() + "^$document" 1004 text: "@@||" + domain.value.toLowerCase() + "^$document"
985 }); 1005 });
986 } 1006 }
987 1007
988 domain.value = ""; 1008 domain.value = "";
989 document.querySelector("#whitelisting .controls") 1009 E("whitelisting-add-button").disabled = true;
990 .classList.remove("mode-edit");
991 } 1010 }
992 1011
993 function editCustomFilters() 1012 function editCustomFilters()
994 { 1013 {
995 let filterTexts = []; 1014 let filterTexts = [];
996 for (let customFilterItem of collections.customFilters.items) 1015 for (let customFilterItem of collections.customFilters.items)
997 filterTexts.push(customFilterItem.text); 1016 filterTexts.push(customFilterItem.text);
998 E("custom-filters-raw").value = filterTexts.join("\n"); 1017 E("custom-filters-raw").value = filterTexts.join("\n");
999 } 1018 }
1000 1019
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 }); 1316 });
1298 ext.backgroundPage.sendMessage({ 1317 ext.backgroundPage.sendMessage({
1299 type: "subscriptions.listen", 1318 type: "subscriptions.listen",
1300 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1319 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1301 "title", "downloadStatus", "downloading"] 1320 "title", "downloadStatus", "downloading"]
1302 }); 1321 });
1303 1322
1304 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1323 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1305 window.addEventListener("hashchange", onHashChange, false); 1324 window.addEventListener("hashchange", onHashChange, false);
1306 } 1325 }
OLDNEW
« new-options.html ('K') | « new-options.html ('k') | skin/new-options.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld