1(function ($) { 2 "use strict"; 3 4 // Função auxiliar para mostrar notificação toast sutil 5 function showToast(message, type) { 6 type = type || 'info'; 7 var $toast = $('<div class="like-toast like-toast-' + type + '">' + message + '</div>'); 8 $('body').append($toast); 9 setTimeout(function() { 10 $toast.addClass('show'); 11 }, 10); 12 setTimeout(function() { 13 $toast.removeClass('show'); 14 setTimeout(function() { 15 $toast.remove(); 16 }, 300); 17 }, 3000); 18 } 19 20 $(document).on("click.like", ".btn-like", function (e) { 21 e.preventDefault(); 22 var $this = $(this), 23 post_id = $this.attr("data-post-id"), 24 site_id = $this.attr("data-site-id"), 25 count = parseInt($this.attr("data-count") || 0), 26 status = "inactive", 27 nonce = ajax.nonce; 28 29 $this = $('[data-post-id="' + post_id + '"]'); 30 31 // Verificar se o usuário está logado - redirecionar diretamente sem confirmação 32 if ($(".user-account").length == 0) { 33 // Salvar URL atual para voltar após login 34 sessionStorage.setItem('like_redirect_after_login', window.location.href); 35 sessionStorage.setItem('like_post_id', post_id); 36 location.href = ajax.login_url; 37 return; 38 } 39 40 // Verificar se o perfil está completo - redirecionar diretamente sem confirmação 41 if (typeof ajax !== 'undefined' && ajax.profile_complete === false) { 42 // Salvar URL atual para voltar após completar perfil 43 sessionStorage.setItem('like_redirect_after_profile', window.location.href); 44 sessionStorage.setItem('like_post_id', post_id); 45 location.href = ajax.complete_profile_url || '/completar-perfil/'; 46 return; 47 } 48 49 // Guardar estado original para reverter em caso de erro 50 var originalActive = $this.hasClass("active"); 51 var originalCount = count; 52 53 // Atualizar UI otimisticamente (feedback imediato) 54 $this.attr("disabled", "disabled"); 55 $this.find(".btn").addClass("disabled"); 56 $this.addClass("loading"); 57 58 if ($this.hasClass("active")) { 59 $this.removeClass("active"); 60 if (count - 1 < 0) count = 0; 61 $this.attr("data-count", count - 1); 62 $this.find(".like-count").html(count - 1); 63 status = "inactive"; 64 } else { 65 status = "active"; 66 $this.addClass("active"); 67 $this.attr("data-count", count + 1); 68 $this.find(".like-count").html(count + 1); 69 } 70 71 $.ajax({ 72 url: ajax.ajax_url, 73 type: "post", 74 dataType: "json", 75 data: { 76 action: "ajax_post_likes", 77 nonce: nonce, 78 post_id: post_id, 79 site_id: site_id, 80 status: status, 81 }, 82 success: function (response) { 83 $this.removeClass("loading"); 84 $this.attr("disabled", false); 85 $this.find(".btn").removeClass("disabled"); 86 87 if (response && response.status === 'success') { 88 // Atualizar contador com valor do servidor 89 if (response.count !== undefined) { 90 $this.attr("data-count", response.count); 91 $this.find(".like-count").html(response.count); 92 } 93 } else if (response && response.status === 'error') { 94 // Reverter mudanças visuais 95 if (originalActive) { 96 $this.addClass("active"); 97 } else { 98 $this.removeClass("active"); 99 } 100 $this.attr("data-count", originalCount); 101 $this.find(".like-count").html(originalCount); 102 103 // Redirecionar silenciosamente se necessário 104 if (response.redirect) { 105 sessionStorage.setItem('like_redirect_after_action', window.location.href); 106 sessionStorage.setItem('like_post_id', post_id); 107 location.href = response.redirect; 108 } else if (response.message) { 109 // Mostrar notificação sutil apenas se não houver redirecionamento 110 showToast(response.message, 'error'); 111 } 112 } 113 }, 114 error: function (xhr, status, error) { 115 // Reverter mudanças visuais em caso de erro 116 if (originalActive) { 117 $this.addClass("active"); 118 } else { 119 $this.removeClass("active"); 120 } 121 $this.attr("data-count", originalCount); 122 $this.find(".like-count").html(originalCount); 123 124 $this.removeClass("loading"); 125 $this.attr("disabled", false); 126 $this.find(".btn").removeClass("disabled"); 127 128 console.error("Erro ao processar like:", error); 129 showToast("Erro ao processar like. Tente novamente.", 'error'); 130 } 131 }); 132 }); 133 134 135 136 137 var classificaButtons = document.querySelectorAll(".btn-class"); 138 139 classificaButtons.forEach((button) => { 140 button.addEventListener("click", (event) => { 141 const postId = button.getAttribute("data-post-id"); 142 let type; 143 144 switch (button.id) { 145 case "top": 146 type = "top"; 147 break; 148 case "geral": 149 default: 150 type = "geral"; 151 break; 152 } 153 154 $.ajax({ 155 url: ajax.ajax_url, 156 type: "post", 157 datatype: "json", 158 data: { 159 action: "ajax_class", 160 post_id: postId, 161 type: type, 162 }, 163 success: function (data) { 164 alert(`Classificada com ${type}`); 165 }, 166 }); 167 }); 168 }); 169 170 171 const requisitar = document.querySelectorAll(".btn-requisitar"); 172 requisitar.forEach((item) => { 173 item.addEventListener("click", () => { 174 const user_id = item.getAttribute("data-user-id"); 175 $.ajax({ 176 url: ajax.ajax_url, 177 type: "post", 178 datatype: "json", 179 data: { 180 action: "ajax_requisitar", 181 user_id, 182 }, 183 success: function (data) { 184 alert(" Valor requisitado com sucesso!"); 185 }, 186 }); 187 }); 188 189 }); 190 191// Log removido - manter apenas erros crÃticos 192})(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.