From be2dc9a1656fcb52520d29cc9ec558200658b89d Mon Sep 17 00:00:00 2001 From: Jonathan Bobel Date: Fri, 15 Mar 2024 10:42:20 -0400 Subject: [PATCH 1/2] 1319 - BUG - adjusting the js to only run when the targeted DOM element exists --- app/assets/javascripts/loginAlert.js | 30 +++++++++++++++++----------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/loginAlert.js b/app/assets/javascripts/loginAlert.js index 84c2ee6a8..b65b14734 100644 --- a/app/assets/javascripts/loginAlert.js +++ b/app/assets/javascripts/loginAlert.js @@ -3,22 +3,28 @@ // Set the target date (10 days before March 15th, 2024) const targetDate = new Date("April 16, 2024 00:00:00").getTime(); +// Set a const for the container to write a conditional statement and only run if it exists + const countdownContainer = document.getElementById("countdown-container"); + // Function to update the countdown display function updateCountdown() { - const now = new Date().getTime(); - const difference = targetDate - now; - // Time calculations for days only - const days = Math.floor(difference / (1000 * 60 * 60 * 24)); + if (countdownContainer) { + const now = new Date().getTime(); + const difference = targetDate - now; - // Visibility logic - if (days < 0 || days > 10) { - // Hide if more than 10 days away OR if already past the date - document.getElementById("countdown-container").style.display = "none"; - } else { - // Show if 10 days or less remaining - document.getElementById("countdown-container").style.display = "block"; - document.getElementById("countdown").innerHTML = days + " days "; + // Time calculations for days only + const days = Math.floor(difference / (1000 * 60 * 60 * 24)); + + // Visibility logic + if (days < 0 || days > 10) { + // Hide if more than 10 days away OR if already past the date + countdownContainer.style.display = "none"; + } else { + // Show if 10 days or less remaining + countdownContainer.style.display = "block"; + document.getElementById("countdown").innerHTML = days + " days "; + } } } From 88c7f9590fc947ef4b0263da8be58146b8685829 Mon Sep 17 00:00:00 2001 From: Carlo Costino Date: Fri, 15 Mar 2024 13:07:50 -0400 Subject: [PATCH 2/2] Removing extraneous space --- app/assets/javascripts/loginAlert.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/loginAlert.js b/app/assets/javascripts/loginAlert.js index b65b14734..e6343c195 100644 --- a/app/assets/javascripts/loginAlert.js +++ b/app/assets/javascripts/loginAlert.js @@ -10,7 +10,7 @@ function updateCountdown() { if (countdownContainer) { - const now = new Date().getTime(); + const now = new Date().getTime(); const difference = targetDate - now; // Time calculations for days only