You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
185 lines
6.1 KiB
185 lines
6.1 KiB
|
|
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(
|
|
$(
|
|
'<svg width="15" height="13" viewBox="0 0 15 13" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M10.7745 1C8.67239 1 7.7426 2.5355 7.54047 3.30325C7.39224 2.5355 6.49748 1 4.10427 1C1.11276 1 -0.221288 4.85199 2.40639 8.14801C4.50853 10.7848 6.705 11.8147 7.54047 12C8.47026 11.8279 10.8311 10.761 12.8363 7.87004C15.3427 4.25632 13.4022 1 10.7745 1Z" stroke="#ff0000" fill="rgba(255, 0, 0, 0.7)"></path></svg>'
|
|
)
|
|
)
|
|
.append(response.count);
|
|
$button.addClass("active");
|
|
} else {
|
|
$button
|
|
.empty()
|
|
.append(
|
|
$(
|
|
'<svg width="15" height="13" viewBox="0 0 15 13" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M10.7745 1C8.67239 1 7.7426 2.5355 7.54047 3.30325C7.39224 2.5355 6.49748 1 4.10427 1C1.11276 1 -0.221288 4.85199 2.40639 8.14801C4.50853 10.7848 6.705 11.8147 7.54047 12C8.47026 11.8279 10.8311 10.761 12.8363 7.87004C15.3427 4.25632 13.4022 1 10.7745 1Z" stroke="#666666" fill="none"></path></svg>'
|
|
)
|
|
)
|
|
.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();
|
|
}
|
|
});
|
|
|