-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: now alert only needs to be removed once and works across pages (#…
…387) * chore: update prettier to adapt to our standards * chore: clean format * unused eslint ignore & markdownlint rule * refactor: Remove unused dark mode JavaScript files and update color mode implementation * config: disable automatic formatting on save and paste in VS Code settings * chore: update .prettierignore to include additional file types * feat: Add esbuild.html partial for building javascript modules with esbuild * refactor: Update color mode implementation and remove unused dark mode JavaScript files * feat: now alert only needs to be removed once and works across pages
- Loading branch information
1 parent
fd2abd8
commit 8efc02a
Showing
6 changed files
with
52 additions
and
33 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
(() => { | ||
"use strict"; | ||
|
||
// Check if alert has been closed, and set data-global-alert to closed | ||
Object.keys(localStorage).forEach(function (key) { | ||
if (/^global-alert-/.test(key)) { | ||
document.documentElement.setAttribute( | ||
"data-global-alert", | ||
"closed" | ||
); | ||
} | ||
}); | ||
|
||
// Enable alert closing, on DOMContentLoaded | ||
window.addEventListener("DOMContentLoaded", () => { | ||
var announcement = document.getElementById("announcement"); | ||
|
||
if (announcement !== null) { | ||
var id = announcement.dataset.id; | ||
|
||
// Check if the alert has been previously closed | ||
if (localStorage.getItem(id) === "closed") { | ||
announcement.style.display = "none"; // Hide the alert if it's closed | ||
} else { | ||
announcement.classList.remove("d-none"); // Show the alert if it's not closed | ||
} | ||
|
||
// Remove other alerts from localStorage and DOM | ||
Object.keys(localStorage).forEach(function (key) { | ||
if (/^global-alert-/.test(key)) { | ||
if (key !== id) { | ||
localStorage.removeItem(key); | ||
document.documentElement.removeAttribute( | ||
"data-global-alert" | ||
); | ||
} | ||
} | ||
}); | ||
|
||
// Event listener for the alert's closing button | ||
var closeButton = announcement.querySelector(".btn-close"); | ||
closeButton.addEventListener("click", function () { | ||
localStorage.setItem(id, "closed"); // Store the closed state in localStorage | ||
}); | ||
} | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters