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

Side by Side Diff: options.js

Issue 29338005: Issue 3761 - Don't clear user input when filter validation failed (Closed)
Patch Set: Created March 9, 2016, 8:14 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 | « messageResponder.js ('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-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 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 while (element) 510 while (element)
511 { 511 {
512 if (element.hasAttribute("data-" + dataName)) 512 if (element.hasAttribute("data-" + dataName))
513 return returnElement ? element : element.getAttribute("data-" + dataName ); 513 return returnElement ? element : element.getAttribute("data-" + dataName );
514 514
515 element = element.parentElement; 515 element = element.parentElement;
516 } 516 }
517 return null; 517 return null;
518 } 518 }
519 519
520 function sendMessageHandleErrors(message, onSuccess)
521 {
522 ext.backgroundPage.sendMessage(message, function(errors)
523 {
524 if (errors.length > 0)
525 alert(errors.join("\n"));
526 else if (onSuccess)
527 onSuccess();
528 });
529 }
530
520 function onClick(e) 531 function onClick(e)
521 { 532 {
522 var context = document.querySelector(".show-context-menu"); 533 var context = document.querySelector(".show-context-menu");
523 if (context) 534 if (context)
524 context.classList.remove("show-context-menu"); 535 context.classList.remove("show-context-menu");
525 536
526 var element = e.target; 537 var element = e.target;
527 while (true) 538 while (true)
528 { 539 {
529 if (!element) 540 if (!element)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 break; 581 break;
571 case "import-subscription": 582 case "import-subscription":
572 var url = E("blockingList-textbox").value; 583 var url = E("blockingList-textbox").value;
573 addEnableSubscription(url); 584 addEnableSubscription(url);
574 closeDialog(); 585 closeDialog();
575 break; 586 break;
576 case "open-dialog": 587 case "open-dialog":
577 openDialog(element.getAttribute("data-dialog")); 588 openDialog(element.getAttribute("data-dialog"));
578 break; 589 break;
579 case "save-custom-filters": 590 case "save-custom-filters":
580 ext.backgroundPage.sendMessage( 591 sendMessageHandleErrors(
581 { 592 {
582 type: "filters.importRaw", 593 type: "filters.importRaw",
583 text: E("custom-filters-raw").value 594 text: E("custom-filters-raw").value
595 },
596 function()
597 {
598 E("custom-filters").classList.remove("mode-edit");
584 }); 599 });
585 E("custom-filters").classList.remove("mode-edit");
586 break; 600 break;
587 case "switch-tab": 601 case "switch-tab":
588 document.body.setAttribute("data-tab", 602 document.body.setAttribute("data-tab",
589 element.getAttribute("data-tab")); 603 element.getAttribute("data-tab"));
590 break; 604 break;
591 case "update-all-subscriptions": 605 case "update-all-subscriptions":
592 ext.backgroundPage.sendMessage( 606 ext.backgroundPage.sendMessage(
593 { 607 {
594 type: "subscriptions.update" 608 type: "subscriptions.update"
595 }); 609 });
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 addWhitelistedDomain(); 689 addWhitelistedDomain();
676 }, false); 690 }, false);
677 691
678 // Advanced tab 692 // Advanced tab
679 var filterTextbox = document.querySelector("#custom-filters-add input"); 693 var filterTextbox = document.querySelector("#custom-filters-add input");
680 placeholderValue = getMessage("options_customFilters_textbox_placeholder"); 694 placeholderValue = getMessage("options_customFilters_textbox_placeholder");
681 filterTextbox.setAttribute("placeholder", placeholderValue); 695 filterTextbox.setAttribute("placeholder", placeholderValue);
682 function addCustomFilters() 696 function addCustomFilters()
683 { 697 {
684 var filterText = filterTextbox.value; 698 var filterText = filterTextbox.value;
685 ext.backgroundPage.sendMessage( 699 sendMessageHandleErrors(
686 { 700 {
687 type: "filters.add", 701 type: "filters.add",
688 text: filterText 702 text: filterText
703 },
704 function()
705 {
706 filterTextbox.value = "";
689 }); 707 });
690 filterTextbox.value = "";
691 } 708 }
692 E("custom-filters-add").addEventListener("submit", function(e) 709 E("custom-filters-add").addEventListener("submit", function(e)
693 { 710 {
694 e.preventDefault(); 711 e.preventDefault();
695 addCustomFilters(); 712 addCustomFilters();
696 }, false); 713 }, false);
697 var customFilterEditButtons = document.querySelectorAll("#custom-filters-edi t-wrapper button"); 714 var customFilterEditButtons = document.querySelectorAll("#custom-filters-edi t-wrapper button");
698 715
699 E("dialog").addEventListener("keydown", function(e) 716 E("dialog").addEventListener("keydown", function(e)
700 { 717 {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 onSubscriptionMessage("added", subscriptions[i]); 817 onSubscriptionMessage("added", subscriptions[i]);
801 }); 818 });
802 }); 819 });
803 } 820 }
804 821
805 function addWhitelistedDomain() 822 function addWhitelistedDomain()
806 { 823 {
807 var domain = E("whitelisting-textbox"); 824 var domain = E("whitelisting-textbox");
808 if (domain.value) 825 if (domain.value)
809 { 826 {
810 ext.backgroundPage.sendMessage( 827 sendMessageHandleErrors(
811 { 828 {
812 type: "filters.add", 829 type: "filters.add",
813 text: "@@||" + domain.value.toLowerCase() + "^$document" 830 text: "@@||" + domain.value.toLowerCase() + "^$document"
814 }); 831 });
815 } 832 }
816 833
817 domain.value = ""; 834 domain.value = "";
818 document.querySelector("#whitelisting .controls").classList.remove("mode-edi t"); 835 document.querySelector("#whitelisting .controls").classList.remove("mode-edi t");
819 } 836 }
820 837
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 { 1003 {
987 case "app.listen": 1004 case "app.listen":
988 if (message.action == "addSubscription") 1005 if (message.action == "addSubscription")
989 { 1006 {
990 var subscription = message.args[0]; 1007 var subscription = message.args[0];
991 var dialog = E("dialog-content-predefined"); 1008 var dialog = E("dialog-content-predefined");
992 dialog.querySelector("h3").textContent = subscription.title || ""; 1009 dialog.querySelector("h3").textContent = subscription.title || "";
993 dialog.querySelector(".url").textContent = subscription.url; 1010 dialog.querySelector(".url").textContent = subscription.url;
994 openDialog("predefined"); 1011 openDialog("predefined");
995 } 1012 }
996 else if (message.action == "error")
997 {
998 alert(message.args.join("\n"));
999 }
1000 break; 1013 break;
1001 case "filters.listen": 1014 case "filters.listen":
1002 onFilterMessage(message.action, message.args[0]); 1015 onFilterMessage(message.action, message.args[0]);
1003 break; 1016 break;
1004 case "subscriptions.listen": 1017 case "subscriptions.listen":
1005 onSubscriptionMessage(message.action, message.args[0]); 1018 onSubscriptionMessage(message.action, message.args[0]);
1006 break; 1019 break;
1007 } 1020 }
1008 }); 1021 });
1009 1022
1010 ext.backgroundPage.sendMessage( 1023 ext.backgroundPage.sendMessage(
1011 { 1024 {
1012 type: "app.listen", 1025 type: "app.listen",
1013 filter: ["addSubscription", "error"] 1026 filter: ["addSubscription", "error"]
1014 }); 1027 });
1015 ext.backgroundPage.sendMessage( 1028 ext.backgroundPage.sendMessage(
1016 { 1029 {
1017 type: "filters.listen", 1030 type: "filters.listen",
1018 filter: ["added", "loaded", "removed"] 1031 filter: ["added", "loaded", "removed"]
1019 }); 1032 });
1020 ext.backgroundPage.sendMessage( 1033 ext.backgroundPage.sendMessage(
1021 { 1034 {
1022 type: "subscriptions.listen", 1035 type: "subscriptions.listen",
1023 filter: ["added", "disabled", "homepage", "lastDownload", "removed", "title" ] 1036 filter: ["added", "disabled", "homepage", "lastDownload", "removed", "title" ]
1024 }); 1037 });
1025 1038
1026 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1039 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1027 })(); 1040 })();
OLDNEW
« no previous file with comments | « messageResponder.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld