Spaces:
Sleeping
Sleeping
document.addEventListener("DOMContentLoaded", function () { | |
const logoLink = document.getElementById("logo-link"); | |
if (logoLink) { | |
logoLink.addEventListener("click", function () { | |
const logo = document.getElementById("logo"); | |
logo.style.transform = "scale(1.5)"; | |
setTimeout(() => { | |
logo.style.transform = "scale(1)"; | |
}, 500); | |
}); | |
} | |
function startProgress() { | |
const progressBar = document.getElementById("progress-bar"); | |
const progressContainer = document.getElementById("progress-container"); | |
const analyzeBtn = document.querySelector("button[type='submit']"); | |
if (progressBar && progressContainer && analyzeBtn) { | |
progressContainer.style.display = "block"; | |
analyzeBtn.disabled = true; | |
analyzeBtn.textContent = "⏳ Analisi in corso..."; | |
let width = 0; | |
const totalTime = 180000; // 3 minutes in milliseconds | |
const intervalTime = totalTime / 100; // Divide the time for each step (to fill the bar in 180s) | |
const interval = setInterval(() => { | |
if (width >= 100) { | |
clearInterval(interval); | |
progressBar.textContent = "100%"; | |
setTimeout(() => { | |
progressContainer.style.display = "none"; // Hide the progress bar after completion | |
}, 1000); // Delay to allow the user to see the completion | |
} else { | |
width += 1; | |
progressBar.style.width = width + "%"; | |
progressBar.textContent = width + "%"; | |
} | |
}, intervalTime); // Update the progress bar at the specified interval time | |
// fallback per riabilitare il pulsante (verrà ignorato se il server risponde prima) | |
setTimeout(() => { | |
analyzeBtn.disabled = false; | |
analyzeBtn.textContent = "Analyze"; | |
progressContainer.style.display = "none"; | |
progressBar.style.width = "0%"; | |
progressBar.textContent = "0%"; | |
}, totalTime + 2000); // Timeout after total time plus extra 2 seconds to hide progress | |
} | |
} | |
window.startProgress = startProgress; | |
const analysisForm = document.getElementById("analysisForm"); | |
if (analysisForm) { | |
analysisForm.addEventListener("submit", function () { | |
startProgress(); | |
}); | |
} | |
const analysisType = document.getElementById("analysis_type"); | |
if (analysisType) { | |
analysisType.addEventListener("change", function () { | |
document.getElementById("pubmed-options").style.display = | |
this.value === "pubmed" ? "block" : "none"; | |
document.getElementById("local-options").style.display = | |
this.value === "local" ? "block" : "none"; | |
}); | |
analysisType.dispatchEvent(new Event("change")); | |
} | |
const fileInput = document.getElementById("pdf_file"); | |
if (fileInput) { | |
fileInput.addEventListener("change", function () { | |
const fileLabel = document.querySelector('label[for="pdf_file"]'); | |
if (fileInput.files.length > 0 && fileLabel) { | |
fileLabel.textContent = `File selected: ${fileInput.files[0].name}`; | |
} | |
}); | |
} | |
const flashMessages = document.querySelectorAll(".error"); | |
if (flashMessages.length > 0) { | |
setTimeout(() => { | |
flashMessages.forEach(message => message.remove()); | |
}, 5000); | |
} | |
}); | |