правки с имиджами
This commit is contained in:
181
js/comment.js
181
js/comment.js
@@ -438,7 +438,7 @@ $doc.on('mouseleave', '.rating-edit-block, #rating_wrapper', function() {
|
||||
|
||||
|
||||
|
||||
// НАЧАЛО $doc.off('click', '.mod_comment_edit')
|
||||
// НАЧАЛО $doc.off('click', '.mod_comment_edit') РЕДАКТИРОВАНИЕ КОММЕНТАРИЯ
|
||||
|
||||
$doc.off('click', '.mod_comment_edit').on('click', '.mod_comment_edit', function(e) {
|
||||
e.preventDefault();
|
||||
@@ -750,63 +750,136 @@ $doc.on('click', '.saveButton', function() {
|
||||
});
|
||||
});
|
||||
|
||||
// Глобальный массив для файлов НОВОГО комментария
|
||||
var newCommentPendingFiles = [];
|
||||
|
||||
// Обработка выбора файлов в основной форме
|
||||
// ДОБАВИЛИ .off('change') чтобы не было дублей
|
||||
$doc.off('change', '#comment_image').on('change', '#comment_image', function() {
|
||||
var files = this.files;
|
||||
var $previewWrapper = $('#image_preview_wrapper');
|
||||
var $errorDisplay = $('#file_error'); // добавили переменную для ошибок
|
||||
|
||||
if (files) {
|
||||
$.each(files, function(i, file) {
|
||||
// --- ТВОЯ ВАЛИДАЦИЯ (Screenshot 7 и 8) ---
|
||||
if (typeof checkFileConsistency === 'function') {
|
||||
if (!checkFileConsistency(file, $errorDisplay)) {
|
||||
return true; // если файл плохой - пропускаем его
|
||||
}
|
||||
}
|
||||
// ------------------------------------------
|
||||
|
||||
newCommentPendingFiles.push(file);
|
||||
var currentIndex = newCommentPendingFiles.length - 1;
|
||||
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(e) {
|
||||
// ПРОВЕРКА: если превью для этого файла уже есть - не добавляем второе
|
||||
if ($previewWrapper.find(`[data-index="${currentIndex}"]`).length > 0) return;
|
||||
|
||||
$previewWrapper.removeClass('d-none'); // показываем только когда есть что показать
|
||||
$previewWrapper.append(`
|
||||
<div class="position-relative new-comment-file-item" data-index="${currentIndex}">
|
||||
<img src="${e.target.result}" class="img-thumbnail" style="width: 80px; height: 80px; object-fit: cover; border: 2px solid #198754;">
|
||||
<button type="button" class="btn btn-danger btn-sm position-absolute top-0 end-0 remove-new-comment-img"
|
||||
style="padding: 0 5px; margin: 2px; line-height: 1;">
|
||||
<i class="bi bi-x-lg" style="font-size: 0.7rem;"></i>
|
||||
</button>
|
||||
</div>`);
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
});
|
||||
}
|
||||
// Очищаем инпут
|
||||
$(this).val('');
|
||||
});
|
||||
|
||||
// Удаление выбранного файла из очереди в новой форме
|
||||
$doc.on('click', '.remove-new-comment-img', function() {
|
||||
var $item = $(this).closest('.new-comment-file-item');
|
||||
var index = $item.data('index');
|
||||
newCommentPendingFiles[index] = null; // Помечаем удаленным
|
||||
$item.fadeOut(200, function() {
|
||||
$(this).remove();
|
||||
if ($('#image_preview_wrapper').children().length === 0) {
|
||||
$('#image_preview_wrapper').addClass('d-none');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Очистка при нажатии кнопки "Сбросить" (reset)
|
||||
$doc.on('click', '#buttonReset', function() {
|
||||
newCommentPendingFiles = [];
|
||||
$('#image_preview_wrapper').empty().addClass('d-none');
|
||||
// Добавляем вот эту строку, чтобы убрать текст ошибки
|
||||
$('#file_error').addClass('d-none').text('');
|
||||
});
|
||||
|
||||
// Отправка новой формы (или ответа)
|
||||
$doc.on('submit', '#mod_comment_new form', function(e) {
|
||||
e.preventDefault();
|
||||
if (!validate(this)) return false;
|
||||
$doc.on('submit', '#mod_comment_new form', function(e) {
|
||||
e.preventDefault();
|
||||
if (!validate(this)) return false;
|
||||
|
||||
var $form = $(this);
|
||||
var $btn = $form.find('[type="submit"]');
|
||||
var originalBtnText = $btn.text();
|
||||
var $form = $(this);
|
||||
var $btn = $form.find('[type="submit"]');
|
||||
var originalBtnText = $btn.text();
|
||||
|
||||
// --- ДОБАВЛЕНА ЛОГИКА ДЛЯ МНОЖЕСТВЕННЫХ ФАЙЛОВ ---
|
||||
var formData = new FormData(this);
|
||||
var fileInput = $form.find('#comment_image')[0];
|
||||
|
||||
if (fileInput && fileInput.files.length > 0) {
|
||||
// Удаляем одиночное поле, чтобы заменить его массивом
|
||||
formData.delete('comment_image');
|
||||
// Добавляем каждый файл в массив comment_image[]
|
||||
for (var i = 0; i < fileInput.files.length; i++) {
|
||||
formData.append('comment_image[]', fileInput.files[i]);
|
||||
}
|
||||
}
|
||||
// ------------------------------------------------
|
||||
// --- ВОТ ЭТОТ БЛОК МЫ ЗАМЕНИЛИ ---
|
||||
var formData = new FormData(this);
|
||||
|
||||
$.ajax({
|
||||
url: aveabspath + 'index.php?ajax=1',
|
||||
type: 'POST',
|
||||
data: formData, // Используем formData с поддержкой нескольких файлов
|
||||
processData: false,
|
||||
contentType: false,
|
||||
xhr: function() {
|
||||
var xhr = new window.XMLHttpRequest();
|
||||
xhr.upload.addEventListener("progress", function(evt) {
|
||||
if (evt.lengthComputable) {
|
||||
var pct = Math.round((evt.loaded / evt.total) * 100);
|
||||
$('#upload_progress_container').removeClass('d-none');
|
||||
$('#upload_progress_bar').css('width', pct + '%');
|
||||
$('#upload_status_text').text('Загрузка: ' + pct + '%');
|
||||
}
|
||||
}, false);
|
||||
return xhr;
|
||||
},
|
||||
beforeSend: function() { $btn.prop('disabled', true).text('Отправка...'); },
|
||||
success: function(data) {
|
||||
if (data.includes('wrong_securecode')) {
|
||||
alert("Код капчи введен неверно!");
|
||||
getCaptha();
|
||||
$btn.prop('disabled', false).text(originalBtnText);
|
||||
$('#upload_progress_container').addClass('d-none');
|
||||
} else { location.reload(); }
|
||||
},
|
||||
error: function() {
|
||||
alert("Ошибка связи с сервером");
|
||||
$btn.prop('disabled', false).text(originalBtnText);
|
||||
$('#upload_progress_container').addClass('d-none');
|
||||
}
|
||||
});
|
||||
});
|
||||
// 1. Удаляем стандартные значения, чтобы они не дублировались из инпута
|
||||
formData.delete('comment_image');
|
||||
formData.delete('comment_image[]');
|
||||
|
||||
// 2. Добавляем файлы из нашего накопленного массива newCommentPendingFiles
|
||||
if (newCommentPendingFiles && newCommentPendingFiles.length > 0) {
|
||||
newCommentPendingFiles.forEach(function(file) {
|
||||
if (file !== null) {
|
||||
formData.append('comment_image[]', file);
|
||||
}
|
||||
});
|
||||
}
|
||||
// ---------------------------------
|
||||
|
||||
$.ajax({
|
||||
url: aveabspath + 'index.php?ajax=1',
|
||||
type: 'POST',
|
||||
data: formData,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
xhr: function() {
|
||||
var xhr = new window.XMLHttpRequest();
|
||||
xhr.upload.addEventListener("progress", function(evt) {
|
||||
if (evt.lengthComputable) {
|
||||
var pct = Math.round((evt.loaded / evt.total) * 100);
|
||||
$('#upload_progress_container').removeClass('d-none');
|
||||
$('#upload_progress_bar').css('width', pct + '%');
|
||||
$('#upload_status_text').text('Загрузка: ' + pct + '%');
|
||||
}
|
||||
}, false);
|
||||
return xhr;
|
||||
},
|
||||
beforeSend: function() { $btn.prop('disabled', true).text('Отправка...'); },
|
||||
success: function(data) {
|
||||
if (data.includes('wrong_securecode')) {
|
||||
alert("Код капчи введен неверно!");
|
||||
getCaptha();
|
||||
$btn.prop('disabled', false).text(originalBtnText);
|
||||
$('#upload_progress_container').addClass('d-none');
|
||||
} else {
|
||||
// Очищаем массив перед перезагрузкой
|
||||
newCommentPendingFiles = [];
|
||||
location.reload();
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
alert("Ошибка связи с сервером");
|
||||
$btn.prop('disabled', false).text(originalBtnText);
|
||||
$('#upload_progress_container').addClass('d-none');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$doc.on('click', '#captcha img, #reload_captcha', function(e) { e.preventDefault(); getCaptha(); });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user