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

Side by Side Diff: options.js

Issue 29339527: Issue 3892 - Disable button if input is invalid when adding subscriptions or filters (Closed)
Patch Set: Created April 6, 2016, 10:43 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-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 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 ext.backgroundPage.sendMessage( 664 ext.backgroundPage.sendMessage(
665 { 665 {
666 type: "subscriptions.remove", 666 type: "subscriptions.remove",
667 url: findParentData(element, "access", false) 667 url: findParentData(element, "access", false)
668 }); 668 });
669 break; 669 break;
670 } 670 }
671 } 671 }
672 } 672 }
673 673
674 function disableButtonWhenInvalid(button, input)
675 {
676 function checkValidity()
677 {
678 button.disabled = !input.checkValidity();
679 }
680 checkValidity();
681 input.addEventListener("input", checkValidity, false);
682 }
683
674 function onDOMLoaded() 684 function onDOMLoaded()
675 { 685 {
676 populateLists(); 686 populateLists();
677 function onFindLanguageKeyUp() 687 function onFindLanguageKeyUp()
678 { 688 {
679 var searchStyle = E("search-style"); 689 var searchStyle = E("search-style");
680 if (!this.value) 690 if (!this.value)
681 searchStyle.innerHTML = ""; 691 searchStyle.innerHTML = "";
682 else 692 else
683 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" + this .value.toLowerCase() + "\"]) { display: none; }"; 693 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" + this .value.toLowerCase() + "\"]) { display: none; }";
(...skipping 29 matching lines...) Expand all
713 723
714 getDocLink("contribute", function(link) 724 getDocLink("contribute", function(link)
715 { 725 {
716 document.querySelector("#tab-contribute a").setAttribute("href", link); 726 document.querySelector("#tab-contribute a").setAttribute("href", link);
717 }); 727 });
718 728
719 updateShareLink(); 729 updateShareLink();
720 730
721 // Initialize interactive UI elements 731 // Initialize interactive UI elements
722 document.body.addEventListener("click", onClick, false); 732 document.body.addEventListener("click", onClick, false);
733 var findLanuage = E("find-language");
723 var placeholderValue = getMessage("options_dialog_language_find"); 734 var placeholderValue = getMessage("options_dialog_language_find");
724 E("find-language").setAttribute("placeholder", placeholderValue); 735 findLanuage.setAttribute("placeholder", placeholderValue);
725 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); 736 findLanuage.addEventListener("keyup", onFindLanguageKeyUp, false);
737 disableButtonWhenInvalid(
738 document.querySelector("[data-action=import-subscription]"),
739 E("blockingList-textbox")
740 );
726 E("whitelisting-textbox").addEventListener("keypress", function(e) 741 E("whitelisting-textbox").addEventListener("keypress", function(e)
727 { 742 {
728 if (getKey(e) == "Enter") 743 if (getKey(e) == "Enter")
729 addWhitelistedDomain(); 744 addWhitelistedDomain();
730 }, false); 745 }, false);
731 746
732 // Advanced tab 747 // Advanced tab
733 var tweaks = document.querySelectorAll("#tweaks li[data-pref]"); 748 var tweaks = document.querySelectorAll("#tweaks li[data-pref]");
734 tweaks = Array.prototype.map.call(tweaks, function(checkbox) 749 tweaks = Array.prototype.map.call(tweaks, function(checkbox)
735 { 750 {
(...skipping 17 matching lines...) Expand all
753 768
754 // Only show option to switch between Safari Content Blockers 769 // Only show option to switch between Safari Content Blockers
755 // and event based blocking if both are available. 770 // and event based blocking if both are available.
756 hidePref("safari_contentblocker", !( 771 hidePref("safari_contentblocker", !(
757 features.safariContentBlocker && 772 features.safariContentBlocker &&
758 "canLoad" in safari.self.tab && 773 "canLoad" in safari.self.tab &&
759 "onbeforeload" in Element.prototype 774 "onbeforeload" in Element.prototype
760 )); 775 ));
761 }); 776 });
762 777
763 var filterTextbox = document.querySelector("#custom-filters-add input"); 778 var filterControl = E("custom-filters-add");
779 var filterTextbox = filterControl.querySelector("input");
764 placeholderValue = getMessage("options_customFilters_textbox_placeholder"); 780 placeholderValue = getMessage("options_customFilters_textbox_placeholder");
765 filterTextbox.setAttribute("placeholder", placeholderValue); 781 filterTextbox.setAttribute("placeholder", placeholderValue);
766 function addCustomFilters() 782 disableButtonWhenInvalid(filterControl.querySelector("button"), filterTextbo x);
783 filterControl.addEventListener("submit", function(e)
767 { 784 {
785 e.preventDefault();
768 var filterText = filterTextbox.value; 786 var filterText = filterTextbox.value;
769 sendMessageHandleErrors( 787 sendMessageHandleErrors(
770 { 788 {
771 type: "filters.add", 789 type: "filters.add",
772 text: filterText 790 text: filterText
773 }, 791 },
774 function() 792 function()
775 { 793 {
776 filterTextbox.value = ""; 794 filterTextbox.value = "";
777 }); 795 });
778 }
779 E("custom-filters-add").addEventListener("submit", function(e)
780 {
781 e.preventDefault();
782 addCustomFilters();
783 }, false); 796 }, false);
784 var customFilterEditButtons = document.querySelectorAll("#custom-filters-edi t-wrapper button"); 797 var customFilterEditButtons = document.querySelectorAll("#custom-filters-edi t-wrapper button");
785 798
786 E("dialog").addEventListener("keydown", function(e) 799 E("dialog").addEventListener("keydown", function(e)
787 { 800 {
788 switch (getKey(e)) 801 switch (getKey(e))
789 { 802 {
790 case "Escape": 803 case "Escape":
791 closeDialog(); 804 closeDialog();
792 break; 805 break;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 focusedBeforeDialog = document.activeElement; 837 focusedBeforeDialog = document.activeElement;
825 defaultFocus.focus(); 838 defaultFocus.focus();
826 } 839 }
827 840
828 function closeDialog() 841 function closeDialog()
829 { 842 {
830 var dialog = E("dialog"); 843 var dialog = E("dialog");
831 dialog.setAttribute("aria-hidden", true); 844 dialog.setAttribute("aria-hidden", true);
832 dialog.removeAttribute("aria-labelledby"); 845 dialog.removeAttribute("aria-labelledby");
833 document.body.removeAttribute("data-dialog"); 846 document.body.removeAttribute("data-dialog");
847 E("blockingList-textbox").value = "";
Sebastian Noack 2016/04/06 22:46:01 This is kinda unrelated, but it seems to have been
834 focusedBeforeDialog.focus(); 848 focusedBeforeDialog.focus();
835 } 849 }
836 850
837 function populateLists() 851 function populateLists()
838 { 852 {
839 subscriptionsMap = Object.create(null); 853 subscriptionsMap = Object.create(null);
840 filtersMap = Object.create(null); 854 filtersMap = Object.create(null);
841 recommendationsMap = Object.create(null); 855 recommendationsMap = Object.create(null);
842 856
843 // Empty collections and lists 857 // Empty collections and lists
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 }); 1181 });
1168 ext.backgroundPage.sendMessage( 1182 ext.backgroundPage.sendMessage(
1169 { 1183 {
1170 type: "subscriptions.listen", 1184 type: "subscriptions.listen",
1171 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1185 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1172 "title", "downloadStatus", "downloading"] 1186 "title", "downloadStatus", "downloading"]
1173 }); 1187 });
1174 1188
1175 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1189 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1176 })(); 1190 })();
OLDNEW

Powered by Google App Engine
This is Rietveld