const homeSwp = new Swiper('.home-swp .swiper', {
slidesPerView: 1,
spaceBetween: 0,
effect: 'fade',
fadeEffect: {
crossFade: true, // Включаем перекрестное затухание
},
allowTouchMove: false,
speed: 750,
loop: true,
navigation: {
nextEl: '.home-swp__btn-next',
prevEl: '.home-swp__btn-prev',
}
})
jQuery(document).ready(function ($) {
$('#ajax-load-blog').on('submit', function (e) {
e.preventDefault()
var data = $(this).serialize()
$.ajax({
url: '/wp-admin/admin-ajax.php', // Use the AJAX URL from wp_localize_script
type: 'POST',
data: data,
success: function (response) {
$(".anons-article__card-wrap").append(response)
$('#page_num').val(Number($('#page_num').val()) + 1)
if (Number($('#page_num').val()) >= Number($('#ajax-load-blog').data('total'))){
$('#ajax-load-blog').hide()
}
},
error: function (error) {
}
});
});
});
jQuery(document).ready(function ($) {
$(".comment-btn button").on("click", function () {
var postId = $(this).data("post-id");
var $button = $(this);
$.ajax({
url: "/wp-admin/admin-ajax.php",
type: "POST",
data: {
action: "add_post_like",
post_id: postId,
},
success: function (response) {
if (response.error) {
alert(response.error);
window.location.href = "/wp-login.php";
return;
}
$(".comment-btn span").text(response.count);
if (response.is_liked) {
$button.addClass("active");
$button.find("svg path").attr({
fill: "rgba(255, 0, 0, 0.7)",
stroke: "#ff0000",
});
} else {
$button.removeClass("active");
$button.find("svg path").attr({
fill: "rgb(18, 18, 18)",
stroke: "#666666",
});
}
},
error: function (error) {
if (error.responseJSON && error.responseJSON.data) {
alert(error.responseJSON.data);
window.location.href = "/wp-login.php";
}
},
});
});
$(document).on("click", ".comment-like-btn", function () {
var commentId = $(this).data("comment-id");
var $button = $(this);
$.ajax({
url: "/wp-admin/admin-ajax.php",
type: "POST",
data: {
action: "add_comment_like",
comment_id: commentId,
},
success: function (response) {
if (response.error) {
alert(response.error);
window.location.href = "/wp-login.php";
return;
}
if (response.is_liked) {
$button
.empty()
.append(
$(
''
)
)
.append(response.count);
$button.addClass("active");
} else {
$button
.empty()
.append(
$(
''
)
)
.append(response.count);
$button.removeClass("active");
}
},
error: function (error) {
if (error.responseJSON && error.responseJSON.data) {
alert(error.responseJSON.data);
window.location.href = "/wp-login.php";
}
},
});
});
function checkLikedPosts() {
if (!document.body.classList.contains("logged-in")) {
return;
}
$.ajax({
url: "/wp-admin/admin-ajax.php",
type: "POST",
data: {
action: "check_user_likes",
},
success: function (response) {
if (response.error) {
return;
}
try {
var data = JSON.parse(response);
if (data.posts && data.posts.length > 0) {
for (var i = 0; i < data.posts.length; i++) {
var $button = $('.comment-btn button[data-post-id="' + data.posts[i] + '"]');
$button.addClass("active");
$button.find("svg path").attr({
fill: "rgba(255, 0, 0, 0.7)",
stroke: "#ff0000",
});
}
}
if (data.comments && data.comments.length > 0) {
for (var j = 0; j < data.comments.length; j++) {
var $commentButton = $('.comment-like-btn[data-comment-id="' + data.comments[j] + '"]');
$commentButton.addClass("active");
$commentButton.find("svg path").attr({
fill: "rgba(255, 0, 0, 0.7)",
stroke: "#ff0000",
});
}
}
} catch (e) {}
},
error: function (error) {},
});
}
if (document.body.classList.contains("logged-in")) {
checkLikedPosts();
}
});