Исправление: кнопка Сканировать не показывалась, т.к. ранний return зависел от закомментированного блока загрузки

This commit is contained in:
apuc committed 2026-09-18 14:20:40 +03:00
1 parent 91c63fd652
commit b419fe2092
1 file changed
+18 -14
+18 -14
View File
@@ -52,10 +52,13 @@
var resultCard = document.getElementById('resultCard'); var resultCard = document.getElementById('resultCard');
var resultContent = document.getElementById('resultContent'); var resultContent = document.getElementById('resultContent');
if (!uploadArea || !fileInput || !analyzeBtn) return; // шорткод не выведен // Блок загрузки может быть закомментирован (осталось только сканирование с камеры),
// поэтому НЕ выходим раньше времени — инициализируем сканирование всегда.
var hasUpload = !!(uploadArea && fileInput && analyzeBtn);
var selectedFile = null; var selectedFile = null;
if (hasUpload) {
uploadArea.addEventListener('click', function () { fileInput.click(); }); uploadArea.addEventListener('click', function () { fileInput.click(); });
uploadArea.addEventListener('dragover', function (e) { uploadArea.addEventListener('dragover', function (e) {
e.preventDefault(); e.preventDefault();
@@ -84,11 +87,12 @@
if (!selectedFile) return; if (!selectedFile) return;
sendVideo(selectedFile, selectedFile.name); sendVideo(selectedFile, selectedFile.name);
}); });
}
async function sendVideo(blob, filename) { async function sendVideo(blob, filename) {
analyzeBtn.disabled = true; if (analyzeBtn) analyzeBtn.disabled = true;
progressContainer.style.display = 'block'; if (progressContainer) progressContainer.style.display = 'block';
resultCard.style.display = 'none'; if (resultCard) resultCard.style.display = 'none';
setProgress(5, 'Загрузка видео...'); setProgress(5, 'Загрузка видео...');
var formData = new FormData(); var formData = new FormData();
@@ -125,7 +129,7 @@
setProgress(100, 'Готово!'); setProgress(100, 'Готово!');
document.getElementById('scanLoader').classList.remove('open'); document.getElementById('scanLoader').classList.remove('open');
setTimeout(function () { setTimeout(function () {
progressContainer.style.display = 'none'; if (progressContainer) progressContainer.style.display = 'none';
renderResult(data); renderResult(data);
}, 300); }, 300);
return; return;
@@ -147,27 +151,27 @@
} }
function setProgress(pct, text) { function setProgress(pct, text) {
progressFill.style.width = pct + '%'; if (progressFill) progressFill.style.width = pct + '%';
progressText.textContent = text; if (progressText) progressText.textContent = text;
} }
function showError(msg, videoUrl) { function showError(msg, videoUrl) {
document.getElementById('scanLoader').classList.remove('open'); document.getElementById('scanLoader').classList.remove('open');
progressContainer.style.display = 'none'; if (progressContainer) progressContainer.style.display = 'none';
resultCard.style.display = 'block'; if (resultCard) resultCard.style.display = 'block';
var html = '<div class="med-error-box"><strong>Ошибка:</strong> ' + escapeHtml(msg) + '</div>'; var html = '<div class="med-error-box"><strong>Ошибка:</strong> ' + escapeHtml(msg) + '</div>';
if (videoUrl) { if (videoUrl) {
html += '<div style="text-align:center; margin-top:15px">' + html += '<div style="text-align:center; margin-top:15px">' +
'<a class="med-btn-download" href="' + downloadUrl(videoUrl) + '">🎬 Скачать записанное видео</a>' + '<a class="med-btn-download" href="' + downloadUrl(videoUrl) + '">🎬 Скачать записанное видео</a>' +
'</div>'; '</div>';
} }
resultContent.innerHTML = html; if (resultContent) resultContent.innerHTML = html;
analyzeBtn.disabled = false; if (analyzeBtn) analyzeBtn.disabled = false;
} }
function renderResult(data) { function renderResult(data) {
document.getElementById('scanLoader').classList.remove('open'); document.getElementById('scanLoader').classList.remove('open');
resultCard.style.display = 'block'; if (resultCard) resultCard.style.display = 'block';
var html = ''; var html = '';
@@ -227,8 +231,8 @@
'</div>'; '</div>';
} }
resultContent.innerHTML = html; if (resultContent) resultContent.innerHTML = html;
resultCard.scrollIntoView({ behavior: 'smooth' }); if (resultCard) resultCard.scrollIntoView({ behavior: 'smooth' });
} }
// Поделиться (глобальная функция для inline-onclick) // Поделиться (глобальная функция для inline-onclick)