normalisation blog + gestion images

This commit is contained in:
2025-12-14 11:42:13 +01:00
parent 1950fd3902
commit b4e037f11d
12 changed files with 367 additions and 289 deletions

View File

@@ -3,6 +3,7 @@ const messages = document.getElementById("messages");
const imgField = document.getElementById("articleImage");
const titleField = document.getElementById("articleTitle");
const imgPreview = document.getElementById("imagePreview");
const contentField = document.getElementById("articleContent");
const categoryField = document.getElementById("articleCategory");
const publishedField = document.getElementById("articlePublished");
@@ -31,6 +32,21 @@ function imageValide(file) {
return ["image/jpeg", "image/png", "image/gif"].includes(file.type);
}
// Preview image on selection
imgField.addEventListener("change", function () {
const file = imgField.files && imgField.files[0];
if (!file || !imageValide(file)) {
if (imgPreview) {
imgPreview.src = "";
imgPreview.classList.add("d-none");
}
return;
}
const url = URL.createObjectURL(file);
imgPreview.src = url;
imgPreview.classList.remove("d-none");
});
form.addEventListener("submit", function (e) {
e.preventDefault();