Use LocalStorage for dialog sessions (#8382)

This change helps avoid friction using the docs site in day-to-day development with Leaflet, while providing the valuable service of presenting the critical Ukrainian message.

Slava Ukraini!
This commit is contained in:
Christopher Wirt
2022-08-01 14:17:53 -07:00
committed by GitHub
parent a64f8bff71
commit 1e97a40b78

View File

@ -3,10 +3,11 @@ var ONE_DAY_MILLI_SEC = 24 * 60 * 60 * 1000;
function openDialog() { function openDialog() {
if (sessionStorage) { // keep the last session timestamp in local storage to
var session = sessionStorage.getItem(SESSION_KEY); // re-show after 24 hours since last ack
// open the dialog only every 24 hours if (localStorage) {
if (session && Date.now() - session < ONE_DAY_MILLI_SEC) { var sessionTimestamp = localStorage.getItem(SESSION_KEY);
if (sessionTimestamp && Date.now() - sessionTimestamp < ONE_DAY_MILLI_SEC) {
return; return;
} }
} }
@ -30,8 +31,8 @@ function openDialog() {
var dialog = document.getElementById('dialog'); var dialog = document.getElementById('dialog');
document.body.removeChild(dialog); document.body.removeChild(dialog);
document.body.classList.remove('overflowHidden'); document.body.classList.remove('overflowHidden');
if (sessionStorage) { if (localStorage) {
sessionStorage.setItem(SESSION_KEY, Date.now()); localStorage.setItem(SESSION_KEY, Date.now());
} }
}); });