mirror of
https://github.com/Leaflet/Leaflet.git
synced 2025-08-03 15:40:43 +00:00
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:
@ -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());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user