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

Side by Side Diff: options.js

Issue 29321417: Issue 2357 - Added "predefined list" dialog to options page (Closed)
Patch Set: Post-review: Merged Created July 16, 2015, 11:36 a.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 | « options.html ('k') | skin/options.css » ('j') | 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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 for (var j = 0; j < this.details.length; j++) 46 for (var j = 0; j < this.details.length; j++)
47 { 47 {
48 var table = E(this.details[j].id); 48 var table = E(this.details[j].id);
49 var template = table.querySelector("template"); 49 var template = table.querySelector("template");
50 for (var i = 0; i < arguments.length; i++) 50 for (var i = 0; i < arguments.length; i++)
51 { 51 {
52 var item = arguments[i]; 52 var item = arguments[i];
53 var text = item.title || item.url || item.text; 53 var text = item.title || item.url || item.text;
54 var listItem = document.createElement("li"); 54 var listItem = document.createElement("li");
55 listItem.appendChild(document.importNode(template.content, true)); 55 listItem.appendChild(document.importNode(template.content, true));
56 listItem.dataset.access = item.url || item.text; 56 listItem.setAttribute("data-access", item.url || item.text);
57 listItem.querySelector(".display").textContent = text; 57 listItem.querySelector(".display").textContent = text;
58 if (text) 58 if (text)
59 listItem.dataset.search = text.toLowerCase(); 59 listItem.setAttribute("data-search", text.toLowerCase());
60 60
61 var control = listItem.querySelector(".control"); 61 var control = listItem.querySelector(".control");
62 if (control) 62 if (control)
63 { 63 {
64 control.addEventListener("click", this.details[j].onClick, false); 64 control.addEventListener("click", this.details[j].onClick, false);
65 control.checked = item.disabled == false; 65 control.checked = item.disabled == false;
66 } 66 }
67 67
68 if (table.hasChildNodes()) 68 if (table.hasChildNodes())
69 table.insertBefore(listItem, table.childNodes[this.items.indexOf(item) ]); 69 table.insertBefore(listItem, table.childNodes[this.items.indexOf(item) ]);
(...skipping 28 matching lines...) Expand all
98 var template = table.querySelector("template"); 98 var template = table.querySelector("template");
99 table.innerHTML = ""; 99 table.innerHTML = "";
100 table.appendChild(template); 100 table.appendChild(template);
101 } 101 }
102 this.items.length = 0; 102 this.items.length = 0;
103 }; 103 };
104 104
105 function onToggleSubscriptionClick(e) 105 function onToggleSubscriptionClick(e)
106 { 106 {
107 e.preventDefault(); 107 e.preventDefault();
108 var subscriptionUrl = e.target.parentNode.dataset.access; 108 var subscriptionUrl = e.target.parentNode.getAttribute("data-access");
109 if (!e.target.checked) 109 if (!e.target.checked)
110 { 110 {
111 ext.backgroundPage.sendMessage( 111 ext.backgroundPage.sendMessage(
112 { 112 {
113 type: "subscriptions.remove", 113 type: "subscriptions.remove",
114 url: subscriptionUrl 114 url: subscriptionUrl
115 }); 115 });
116 } 116 }
117 else 117 else
118 addEnableSubscription(subscriptionUrl); 118 addEnableSubscription(subscriptionUrl);
119 } 119 }
120 120
121 function onAddLanguageSubscriptionClick(e) 121 function onAddLanguageSubscriptionClick(e)
122 { 122 {
123 e.preventDefault(); 123 e.preventDefault();
124 var url = this.parentNode.dataset.access; 124 var url = this.parentNode.getAttribute("data-access");
125 addEnableSubscription(url); 125 addEnableSubscription(url);
126 } 126 }
127 127
128 function onRemoveFilterClick() 128 function onRemoveFilterClick()
129 { 129 {
130 var filter = this.parentNode.dataset.access; 130 var filter = this.parentNode.getAttribute("data-access");
131 ext.backgroundPage.sendMessage( 131 ext.backgroundPage.sendMessage(
132 { 132 {
133 type: "filters.remove", 133 type: "filters.remove",
134 text: filter 134 text: filter
135 }); 135 });
136 } 136 }
137 137
138 collections.popular = new Collection( 138 collections.popular = new Collection(
139 [ 139 [
140 { 140 {
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 if (element.getAttribute("popular")) 324 if (element.getAttribute("popular"))
325 recommendation.isPopular = true; 325 recommendation.isPopular = true;
326 326
327 recommendationsMap[subscription.url] = recommendation; 327 recommendationsMap[subscription.url] = recommendation;
328 updateSubscription(subscription); 328 updateSubscription(subscription);
329 } 329 }
330 }, false); 330 }, false);
331 request.send(null); 331 request.send(null);
332 } 332 }
333 333
334 function onClick(e)
335 {
336 var element = e.target;
337 while (true)
338 {
339 if (!element)
340 return;
341
342 if (element.hasAttribute("data-action"))
343 break;
344
345 element = element.parentElement;
346 }
347
348 var actions = element.getAttribute("data-action").split(",");
349 for (var i = 0; i < actions.length; i++)
350 {
351 switch (actions[i])
352 {
353 case "add-domain-exception":
354 addWhitelistedDomain();
355 break;
356 case "add-predefined-subscription":
357 var dialog = E("dialog-content-predefined");
358 var title = dialog.querySelector("h3").textContent;
359 var url = dialog.querySelector(".url").textContent;
360 addEnableSubscription(url, title);
361 document.body.removeAttribute("data-dialog");
362 break;
363 case "cancel-custom-filters":
364 E("custom-filters").classList.remove("mode-edit");
saroyanm 2015/07/16 12:32:27 Strange, classList according to MDN is supported s
Sebastian Noack 2015/07/16 12:36:50 As I already told you in a different comment, it's
saroyanm 2015/07/16 12:41:01 Ahh right your reference to caniuse went out of my
365 break;
366 case "cancel-domain-exception":
367 E("whitelisting-textbox").value = "";
368 break;
369 case "close-dialog":
370 document.body.removeAttribute("data-dialog");
371 break;
372 case "edit-custom-filters":
373 E("custom-filters").classList.add("mode-edit");
374 editCustomFilters();
375 break;
376 case "import-subscription":
377 var url = E("blockingList-textbox").value;
378 addEnableSubscription(url);
379 document.body.removeAttribute("data-dialog");
380 break;
381 case "open-dialog":
382 openDialog(element.getAttribute("data-dialog"));
383 break;
384 case "save-custom-filters":
385 ext.backgroundPage.sendMessage(
386 {
387 type: "filters.importRaw",
388 text: E("custom-filters-raw").value
389 });
390 E("custom-filters").classList.remove("mode-edit");
391 break;
392 case "switch-tab":
393 document.body.setAttribute("data-tab",
394 element.getAttribute("data-tab"));
395 break;
396 }
397 }
398 }
399
334 function onDOMLoaded() 400 function onDOMLoaded()
335 { 401 {
336 var recommendationTemplate = document.querySelector("#recommend-list-table t emplate"); 402 var recommendationTemplate = document.querySelector("#recommend-list-table t emplate");
337 var popularText = ext.i18n.getMessage("options_popular"); 403 var popularText = ext.i18n.getMessage("options_popular");
338 recommendationTemplate.content.querySelector(".popular").textContent = popul arText; 404 recommendationTemplate.content.querySelector(".popular").textContent = popul arText;
339 var languagesTemplate = document.querySelector("#all-lang-table template"); 405 var languagesTemplate = document.querySelector("#all-lang-table template");
340 var buttonText = ext.i18n.getMessage("options_button_add"); 406 var buttonText = ext.i18n.getMessage("options_button_add");
341 languagesTemplate.content.querySelector(".button-add span").textContent = bu ttonText; 407 languagesTemplate.content.querySelector(".button-add span").textContent = bu ttonText;
342 408
343 populateLists(); 409 populateLists();
344 410
345 var tabList = document.querySelectorAll("#main-navigation-tabs li");
346 for (var i = 0; i < tabList.length; i++)
347 {
348 tabList[i].addEventListener("click", function(e)
349 {
350 document.body.dataset.tab = e.currentTarget.dataset.show;
351 }, false);
352 }
353
354 function onFindLanguageKeyUp() 411 function onFindLanguageKeyUp()
355 { 412 {
356 var searchStyle = E("search-style"); 413 var searchStyle = E("search-style");
357 if (!this.value) 414 if (!this.value)
358 searchStyle.innerHTML = ""; 415 searchStyle.innerHTML = "";
359 else 416 else
360 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" + this .value.toLowerCase() + "\"]) { display: none; }"; 417 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" + this .value.toLowerCase() + "\"]) { display: none; }";
361 } 418 }
362 419
363 function isEnterPressed(e) 420 function isEnterPressed(e)
(...skipping 20 matching lines...) Expand all
384 }); 441 });
385 442
386 getDocLink("contribute", function(link) 443 getDocLink("contribute", function(link)
387 { 444 {
388 document.querySelector("#tab-contribute a").setAttribute("href", link); 445 document.querySelector("#tab-contribute a").setAttribute("href", link);
389 }); 446 });
390 447
391 updateShareLink(); 448 updateShareLink();
392 449
393 // Initialize interactive UI elements 450 // Initialize interactive UI elements
451 document.body.addEventListener("click", onClick, false);
394 var placeholderValue = ext.i18n.getMessage("options_dialog_language_find"); 452 var placeholderValue = ext.i18n.getMessage("options_dialog_language_find");
395 E("find-language").setAttribute("placeholder", placeholderValue); 453 E("find-language").setAttribute("placeholder", placeholderValue);
396 E("add-blocking-list").addEventListener("click", function()
397 {
398 openDialog("customlist");
399 }, false);
400 E("add-website-language").addEventListener("click", function()
401 {
402 openDialog("language");
403 }, false);
404 E("dialog-close").addEventListener("click", function()
405 {
406 delete document.body.dataset.dialog;
407 }, false);
408 E("edit-ownBlockingList-button").addEventListener("click", editCustomFilters , false);
409 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); 454 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false);
410 E("whitelisting").addEventListener("click", function(e)
411 {
412 var id = e.target.id;
413 if (id == "whitelisting-add-icon" || id == "whitelisting-enter-icon")
414 addWhitelistedDomain();
415 else if (id == "whitelisting-cancel-button")
416 E("whitelisting-textbox").value = "";
417 }, false);
418 E("whitelisting-add-button").addEventListener("click", addWhitelistedDomain, false);
419 E("whitelisting-textbox").addEventListener("keypress", function(e) 455 E("whitelisting-textbox").addEventListener("keypress", function(e)
420 { 456 {
421 if (isEnterPressed(e)) 457 if (isEnterPressed(e))
422 addWhitelistedDomain(); 458 addWhitelistedDomain();
423 }, false); 459 }, false);
424 E("import-blockingList-button").addEventListener("click", function()
425 {
426 var url = E("blockingList-textbox").value;
427 addEnableSubscription(url);
428 delete document.body.dataset.dialog;
429 }, false);
430 460
431 // Advanced tab 461 // Advanced tab
432 var filterTextbox = document.querySelector("#custom-filters-add input"); 462 var filterTextbox = document.querySelector("#custom-filters-add input");
433 placeholderValue = ext.i18n.getMessage("options_customFilters_textbox_placeh older"); 463 placeholderValue = ext.i18n.getMessage("options_customFilters_textbox_placeh older");
434 filterTextbox.setAttribute("placeholder", placeholderValue); 464 filterTextbox.setAttribute("placeholder", placeholderValue);
435 function addCustomFilters() 465 function addCustomFilters()
436 { 466 {
437 var filterText = filterTextbox.value; 467 var filterText = filterTextbox.value;
438 ext.backgroundPage.sendMessage( 468 ext.backgroundPage.sendMessage(
439 { 469 {
440 type: "filters.add", 470 type: "filters.add",
441 text: filterText 471 text: filterText
442 }); 472 });
443 filterTextbox.value = ""; 473 filterTextbox.value = "";
444 } 474 }
445 E("custom-filters-add").addEventListener("submit", function(e) 475 E("custom-filters-add").addEventListener("submit", function(e)
446 { 476 {
447 e.preventDefault(); 477 e.preventDefault();
448 addCustomFilters(); 478 addCustomFilters();
449 }, false); 479 }, false);
450 var customFilterEditButtons = document.querySelectorAll("#custom-filters-edi t-wrapper button"); 480 var customFilterEditButtons = document.querySelectorAll("#custom-filters-edi t-wrapper button");
451 E("custom-filters-edit-wrapper").addEventListener("click", function(e)
452 {
453 var target = null;
454 if (e.target.localName == "button")
455 target = e.target;
456 else if (e.target.parentElement.localName == "button")
457 target = e.target.parentElement;
458 else
459 return;
460
461 var id = target.id;
462 E("custom-filters").classList.toggle("mode-edit");
463 if (id == "custom-filters-show-edit")
464 editCustomFilters();
465 else if (id == "custom-filters-raw-save")
466 {
467 ext.backgroundPage.sendMessage(
468 {
469 type: "filters.importRaw",
470 text: E("custom-filters-raw").value
471 });
472 }
473 }, false);
474 } 481 }
475 482
476 function openDialog(name) 483 function openDialog(name)
477 { 484 {
478 document.body.dataset.dialog = name; 485 document.body.setAttribute("data-dialog", name);
479 } 486 }
480 487
481 function populateLists() 488 function populateLists()
482 { 489 {
483 subscriptionsMap = Object.create(null); 490 subscriptionsMap = Object.create(null);
484 filtersMap = Object.create(null); 491 filtersMap = Object.create(null);
485 recommendationsMap = Object.create(null); 492 recommendationsMap = Object.create(null);
486 493
487 // Empty collections and lists 494 // Empty collections and lists
488 for (var property in collections) 495 for (var property in collections)
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 } 656 }
650 updateShareLink(); 657 updateShareLink();
651 }); 658 });
652 break; 659 break;
653 case "title": 660 case "title":
654 // TODO: NYI 661 // TODO: NYI
655 break; 662 break;
656 } 663 }
657 } 664 }
658 665
659 function showAddSubscriptionDialog(subscription)
660 {
661 E("blockingList-textbox").value = subscription.url;
662 openDialog("customlist");
663 }
664
665 function updateShareLink() 666 function updateShareLink()
666 { 667 {
667 ext.backgroundPage.sendMessage( 668 ext.backgroundPage.sendMessage(
668 { 669 {
669 type: "filters.blocked", 670 type: "filters.blocked",
670 url: "https://platform.twitter.com/widgets/", 671 url: "https://platform.twitter.com/widgets/",
671 requestType: "SCRIPT", 672 requestType: "SCRIPT",
672 docDomain: "adblockplus.org", 673 docDomain: "adblockplus.org",
673 thirdParty: true 674 thirdParty: true
674 }, 675 },
(...skipping 18 matching lines...) Expand all
693 }, callback); 694 }, callback);
694 } 695 }
695 696
696 ext.onMessage.addListener(function(message) 697 ext.onMessage.addListener(function(message)
697 { 698 {
698 switch (message.type) 699 switch (message.type)
699 { 700 {
700 case "app.listen": 701 case "app.listen":
701 if (message.action == "addSubscription") 702 if (message.action == "addSubscription")
702 { 703 {
703 E("blockingList-textbox").value = message.args[0].url; 704 var subscription = message.args[0];
704 openDialog("customlist"); 705 var dialog = E("dialog-content-predefined");
706 dialog.querySelector("h3").textContent = subscription.title || "";
707 dialog.querySelector(".url").textContent = subscription.url;
708 openDialog("predefined");
705 } 709 }
706 else if (message.action == "error") 710 else if (message.action == "error")
707 { 711 {
708 alert(message.args.join("\n")); 712 alert(message.args.join("\n"));
709 } 713 }
710 break; 714 break;
711 case "filters.listen": 715 case "filters.listen":
712 onFilterMessage(message.action, message.args[0]); 716 onFilterMessage(message.action, message.args[0]);
713 break; 717 break;
714 case "subscriptions.listen": 718 case "subscriptions.listen":
(...skipping 13 matching lines...) Expand all
728 filter: ["added", "loaded", "removed"] 732 filter: ["added", "loaded", "removed"]
729 }); 733 });
730 ext.backgroundPage.sendMessage( 734 ext.backgroundPage.sendMessage(
731 { 735 {
732 type: "subscriptions.listen", 736 type: "subscriptions.listen",
733 filter: ["added", "disabled", "homepage", "removed", "title"] 737 filter: ["added", "disabled", "homepage", "removed", "title"]
734 }); 738 });
735 739
736 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 740 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
737 })(); 741 })();
OLDNEW
« no previous file with comments | « options.html ('k') | skin/options.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld