Пока нет похожих игр. Станьте первым, кто предложит похожие игры!
');
var confirmContent = $(
'
' +
'' +
'
' +
'
' + message + '
' +
'
' +
'' +
'
'
);
confirmModal.append(confirmContent);
$('body').append(confirmModal);
// Показываем с анимацией
setTimeout(function() {
confirmModal.addClass('show');
}, 10);
// Обработчики кнопок
confirmModal.find('.confirm-ok').on('click', function() {
confirmModal.removeClass('show');
setTimeout(function() {
confirmModal.remove();
if (typeof onConfirm === 'function') {
onConfirm();
}
}, 300);
});
confirmModal.find('.confirm-cancel').on('click', function() {
confirmModal.removeClass('show');
setTimeout(function() {
confirmModal.remove();
if (typeof onCancel === 'function') {
onCancel();
}
}, 300);
});
// Закрытие по клику на фон
confirmModal.on('click', function(e) {
if ($(e.target).hasClass('confirm-dialog-modal')) {
confirmModal.removeClass('show');
setTimeout(function() {
confirmModal.remove();
if (typeof onCancel === 'function') {
onCancel();
}
}, 300);
}
});
// Закрытие по Escape
$(document).on('keyup.confirmDialog', function(e) {
if (e.key === 'Escape' && confirmModal.hasClass('show')) {
confirmModal.removeClass('show');
setTimeout(function() {
confirmModal.remove();
if (typeof onCancel === 'function') {
onCancel();
}
}, 300);
$(document).off('keyup.confirmDialog');
}
});
}
// Модальное окно
$('#open-similar-modal').on('click', function() {
$('#similar-modal').addClass('open');
$('#similar_game').focus();
updateModalCloseBehavior(); // Добавляем проверку при открытии
});
function closeModal() {
// Проверяем, есть ли добавленные игры или текст
var hasGames = $('#similar-chosen-games .ask_pop_up_tag_item').length > 0;
var hasText = $('#similar_explain').val().trim().length > 0;
if (hasGames || hasText) {
// Показываем кастомное окно подтверждения при наличии изменений
showConfirmDialog(
'Несохраненные изменения',
'У вас есть несохраненные изменения. Закрыть окно без сохранения?',
function() {
// Подтверждено - закрываем
performCloseModal();
},
function() {
// Отменено - ничего не делаем
}
);
} else {
// Закрываем без подтверждения, если нет изменений
performCloseModal();
}
}
function performCloseModal() {
$('#similar-modal').removeClass('open');
$('#similar_game').val('');
$('#similar-search-results').hide().empty();
$('#similar-chosen-games').hide().empty();
$('#similar_explain').val('').parent().hide();
}
function updateModalCloseBehavior() {
// Функция обновляет информацию о возможности закрытия
var hasGames = $('#similar-chosen-games .ask_pop_up_tag_item').length > 0;
var hasText = $('#similar_explain').val().trim().length > 0;
var canClose = !(hasGames || hasText);
// Сохраняем информацию о возможности закрытия
$('#similar-modal').data('can-close', canClose);
}
$('#similar-modal').on('click', function(e) {
// Закрытие по клику на фон - теперь с проверкой
if (e.target === this) {
closeModal();
}
});
$(document).on('keyup', function(e) {
// Закрытие по Escape - теперь с проверкой
if (e.key === 'Escape' && $('#similar-modal').hasClass('open')) {
closeModal();
}
});
// Поиск игр
$('#similar_game').on('input', function() {
var searchTerm = $(this).val().trim();
if(searchTerm.length 0) {
var html = '';
$.each(response.games, function(index, game) {
html += '
' +
' ' + game.title +
'
';
});
resultsContainer.html(html).show();
} else {
resultsContainer.html('
Игры не найдены
').show();
}
}
});
});
// Выбор игры
$(document).on('click', '#similar-search-results .search-result-item', function() {
var gameId = $(this).data('id');
var gameTitle = $(this).data('title');
if($('#similar-chosen-games').find('[data-gameid="' + gameId + '"]').length > 0) {
window.gameInteractive.showNotification('Предупреждение', 'Эта игра уже добавлена', 'warning');
return;
}
var tagHtml = '
';
if($('#similar-chosen-games').is(':hidden')) {
$('#similar-chosen-games').html('
World of Outlaws: Dirt Racing 24 похожа на:').show();
}
$('#similar-chosen-games').append(tagHtml);
if($('#similar-chosen-games .ask_pop_up_tag_item').length > 0) {
$('#similar_explain').parent().show();
}
$('#similar_game').val('');
$('#similar-search-results').hide().empty();
// Обновляем поведение закрытия после добавления игры
updateModalCloseBehavior();
});
// Удаление игры
$(document).on('click', '.del_tag', function(e) {
e.preventDefault();
$(this).closest('.ask_pop_up_tag_item').remove();
if($('#similar-chosen-games .ask_pop_up_tag_item').length === 0) {
$('#similar-chosen-games').hide().empty();
$('#similar_explain').val('').parent().hide();
}
// Обновляем поведение закрытия после удаления игры
updateModalCloseBehavior();
});
// Отслеживаем изменения в текстовом поле объяснения
$('#similar_explain').on('input', function() {
updateModalCloseBehavior();
});
// Крестик в заголовке модального окна
$('.close-modal').on('click', function() {
closeModal();
});
// Кнопка "Отмена"
$('#cancel-similar-games').on('click', function() {
closeModal();
});
// Сохранение
$('#save-similar-games').on('click', function() {
var selectedGames = [];
$('#similar-chosen-games .ask_pop_up_tag_item').each(function() {
selectedGames.push({
id: $(this).data('gameid'),
title: $(this).text().replace(' ×', '')
});
});
if(selectedGames.length === 0) {
window.gameInteractive.showNotification('Предупреждение', 'Выберите хотя бы одну игру', 'warning');
return;
}
var explanation = $('#similar_explain').val().trim();
if(explanation === '') {
explanation = 'Похожа по мнению пользователя';
}
var saveButton = $(this);
saveButton.prop('disabled', true).html('
Отправляем...');
var gamesSent = 0;
var gamesTotal = selectedGames.length;
var successCount = 0;
var errorCount = 0;
selectedGames.forEach(function(game) {
$.ajax({
url: window.location.href,
method: 'POST',
dataType: 'json',
data: {
similar_action: 'add_similar',
similar_game_id: game.id,
explanation: explanation
},
success: function(response) {
gamesSent++;
if(response.success) {
successCount++;
} else if(response.error) {
errorCount++;
window.gameInteractive.showNotification('Ошибка', response.error, 'error');
}
if(gamesSent === gamesTotal) {
if(successCount > 0) {
window.gameInteractive.showNotification('Успешно!', successCount + ' из ' + gamesTotal + ' игр отправлены на модерацию!', 'success');
performCloseModal(); // Используем performCloseModal вместо closeModal
setTimeout(() => location.reload(), 1500);
}
saveButton.prop('disabled', false).html('Сохранить');
}
},
error: function() {
gamesSent++;
errorCount++;
if(gamesSent === gamesTotal) {
window.gameInteractive.showNotification('Ошибка', 'Произошла ошибка при отправке', 'error');
saveButton.prop('disabled', false).html('Сохранить');
}
}
});
});
});
// Голосование за похожие игры
$(document).on('click', '.vote-like-btn:not(.active)', function() {
var button = $(this);
var gameId = button.data('game-id');
var gameItem = button.closest('.similar-game-item');
button.prop('disabled', true).html('
');
$.ajax({
url: window.location.href,
method: 'POST',
dataType: 'json',
data: {
similar_action: 'vote_similar',
similar_game_id: gameId,
vote_type: 'like'
},
success: function(response) {
if(response.success) {
// Используем общие функции из interactive.js
gameItem.find('.like-count').each(function() {
window.gameInteractive.animateCounter(this, response.likes);
});
gameItem.find('.dislike-count').each(function() {
window.gameInteractive.animateCounter(this, response.dislikes);
});
button.addClass('active').prop('disabled', true).html('
Похожа');
gameItem.find('.vote-dislike-btn').removeClass('active').prop('disabled', false).html('
Не похожа');
window.gameInteractive.showNotification('Спасибо!', 'Ваш голос учтен!', 'success');
button.addClass('interactive-animate');
setTimeout(() => button.removeClass('interactive-animate'), 300);
} else if(response.error) {
window.gameInteractive.showNotification('Предупреждение', response.error, 'warning');
button.prop('disabled', false).html('
Похожа');
}
},
error: function() {
window.gameInteractive.showNotification('Ошибка', 'Ошибка при голосовании', 'error');
button.prop('disabled', false).html('
Похожа');
}
});
});
$(document).on('click', '.vote-dislike-btn:not(.active)', function() {
var button = $(this);
var gameId = button.data('game-id');
var gameItem = button.closest('.similar-game-item');
button.prop('disabled', true).html('
');
$.ajax({
url: window.location.href,
method: 'POST',
dataType: 'json',
data: {
similar_action: 'vote_similar',
similar_game_id: gameId,
vote_type: 'dislike'
},
success: function(response) {
if(response.success) {
// Используем общие функции из interactive.js
gameItem.find('.like-count').each(function() {
window.gameInteractive.animateCounter(this, response.likes);
});
gameItem.find('.dislike-count').each(function() {
window.gameInteractive.animateCounter(this, response.dislikes);
});
button.addClass('active').prop('disabled', true).html('
Не похожа');
gameItem.find('.vote-like-btn').removeClass('active').prop('disabled', false).html('
Похожа');
window.gameInteractive.showNotification('Спасибо!', 'Ваш голос учтен!', 'success');
button.addClass('interactive-animate');
setTimeout(() => button.removeClass('interactive-animate'), 300);
} else if(response.error) {
window.gameInteractive.showNotification('Предупреждение', response.error, 'warning');
button.prop('disabled', false).html('
Не похожа');
}
},
error: function() {
window.gameInteractive.showNotification('Ошибка', 'Ошибка при голосовании', 'error');
button.prop('disabled', false).html('
Не похожа');
}
});
});
// Закрытие результатов поиска
$(document).on('click', function(e) {
if (!$(e.target).closest('#similar_game, #similar-search-results').length) {
$('#similar-search-results').hide().empty();
}
});
});
Back to top button