Skip to content

Commit

Permalink
Merge pull request #1320 from GSA/1319-bug-js-broken-on-non-sign-in-p…
Browse files Browse the repository at this point in the history
…ages

1319 - BUG - adjusting the js to only run when the targeted DOM element exists
  • Loading branch information
ccostino authored Mar 15, 2024
2 parents dea7f28 + 88c7f95 commit 6b31e5f
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions app/assets/javascripts/loginAlert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));

// 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 ";

if (countdownContainer) {
const now = new Date().getTime();
const difference = targetDate - now;

// 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 ";
}
}

}
Expand Down

0 comments on commit 6b31e5f

Please sign in to comment.