From 4a02b75a4dd2065d9174bbdfee98275c044f902f Mon Sep 17 00:00:00 2001 From: nicoagostini Date: Wed, 14 May 2025 12:53:58 -0700 Subject: [PATCH] fix/Footer scripts moved to a dedicated file --- src/public/scripts/footer.js | 27 +++++++++++++++++++++++++++ src/views/partials/footer.ejs | 30 +----------------------------- 2 files changed, 28 insertions(+), 29 deletions(-) create mode 100644 src/public/scripts/footer.js diff --git a/src/public/scripts/footer.js b/src/public/scripts/footer.js new file mode 100644 index 0000000..7bdc130 --- /dev/null +++ b/src/public/scripts/footer.js @@ -0,0 +1,27 @@ +const factButton = document.getElementById("factButton"); +const factMenu = document.getElementById("factMenu"); +const factInput = document.getElementById("factInput"); +const factSubmitButton = document.getElementById("factSubmitButton"); + +factButton.addEventListener("click", () => { + factMenu.classList.toggle("hidden"); +}); +factSubmitButton.addEventListener("click", () => { + fetch("/fact", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + fact: factInput.value, + }), + }) + .then(response => response.json()) + .then(data => { + Swal.fire('Here is a fact!', data.fact, 'success'); + }) + .catch(error => { + console.error("Error fetching fact:", error); + Swal.fire('Error fetching fact', 'Please try again later', 'error'); + }); +}); \ No newline at end of file diff --git a/src/views/partials/footer.ejs b/src/views/partials/footer.ejs index f6d1596..9f828cf 100644 --- a/src/views/partials/footer.ejs +++ b/src/views/partials/footer.ejs @@ -21,34 +21,6 @@ - + \ No newline at end of file