1(function($) { 2 3 "use strict"; 4 5 const HelpfulPlugin = { 6 el: ".helpful", 7 vote: "helpful_save_vote", 8 feedback: "helpful_save_feedback", 9 helpful: helpful, 10 initPlugin: function() { 11 const self = this; 12 13 // todo, for instances 14 if (window.performance) { 15 if (2 === performance.navigation.type) { 16 self.hasUserVoted(); 17 } 18 } 19 20 if (self.el.length < 1) { 21 return; 22 } 23 24 $(document).on("click", ".helpful .helpful-controls button", function(e) { 25 e.preventDefault(); 26 27 var currentButton = $(this); 28 var currentForm = $(currentButton).closest(".helpful"); 29 var ajaxData = {}; 30 31 $.extend(ajaxData, helpful.ajax_data); 32 $.extend(ajaxData, $(currentButton).data()); 33 34 ajaxData.action = self.vote; 35 36 $(".helpful .helpful-controls button").prop("disabled", true); 37 38 var request = self.ajaxRequest(ajaxData); 39 40 request.done(function(response) { 41 $(currentForm).find(".helpful-header").remove(); 42 $(currentForm).find(".helpful-controls").remove(); 43 $(currentForm).find(".helpful-footer").remove(); 44 $(currentForm).find(".helpful-content").html(response); 45 self.feedbackForm(currentForm); 46 }); 47 }); 48 49 $.each($(".helpful"), function() { 50 var currentContainer = $(this); 51 52 if ($(currentContainer).is(".helpful-prevent-form")) { 53 self.feedbackForm(currentContainer); 54 } 55 56 if ($(currentContainer).find(".helpful-toggle-feedback").length) { 57 $(currentContainer).find(".helpful-toggle-feedback").click(function(e) { 58 e.preventDefault(); 59 $(this).parent().find("div").removeAttr("hidden"); 60 $(this).remove(); 61 }); 62 } 63 }); 64 }, 65 feedbackForm: function(currentForm) { 66 var self = this; 67 68 $(currentForm).on("click", ".helpful-cancel", function(e) { 69 e.preventDefault(); 70 71 var ajaxData = { 72 "action": "helpful_save_feedback", 73 "cancel": 1, 74 "type": $(currentForm).find("[name='type']").val(), 75 "_wpnonce": $(currentForm).find("[name='_wpnonce']").val(), 76 "post_id": $(currentForm).find("[name='post_id']").val(), 77 }; 78 79 $(this).prop("disabled", true); 80 81 var request = self.ajaxRequest(ajaxData); 82 83 request.done(function(response) { 84 $(currentForm).find(".helpful-content").html(response); 85 }); 86 }); 87 88 $(currentForm).on("submit", ".helpful-feedback-form", function(e) { 89 e.preventDefault(); 90 91 var formData = $(this).serializeArray(); 92 var ajaxData = {}; 93 94 $.each(formData, function(i, field) { 95 ajaxData[field.name] = field.value; 96 }); 97 98 $(currentForm).remove(".danger"); 99 100 let key; 101 let required = []; 102 103 $(currentForm).find("[required]").each(function() { 104 if (!$.trim(this.value).length) { 105 $(this).after("<req class=\"danger\">" + helpful.translations.fieldIsRequired + "</req>"); 106 required.push(key); 107 } 108 }); 109 110 if (required.length) { 111 return; 112 } 113 114 var request = self.ajaxRequest(ajaxData); 115 116 request.done(function(response) { 117 $(currentForm).find(".helpful-content").html(response); 118 }); 119 }); 120 }, 121 // todo, for instances 122 hasUserVoted: function() { 123 const self = this; 124 125 let ajaxData = this.helpful.user_voted; 126 127 $(self.el).hide(); 128 129 let request = self.ajaxRequest(ajaxData); 130 131 request.done(function(response) { 132 if (response.success) { 133 $(self.el).remove(); 134 } else { 135 $(self.el).show(); 136 } 137 }); 138 139 return; 140 }, 141 ajaxRequest: function(data) { 142 if (typeof this.helpful.ajax_session !== "undefined") { 143 data.session = this.helpful.ajax_session; 144 } 145 146 return $.ajax({ 147 url: this.helpful.ajax_url, 148 data: data, 149 method: "POST", 150 cache: false, 151 }); 152 }, 153 }; 154 155 $(function() { 156 HelpfulPlugin.initPlugin(); 157 }); 158 159})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.