feat: changeable global alert + fix: cumulative layout shift

This commit is contained in:
Henk Verlinde
2022-01-14 12:14:35 +01:00
parent 7123e6dfae
commit 04a5b32ee5
9 changed files with 35 additions and 22 deletions

5
assets/js/alert-init.js Normal file
View File

@ -0,0 +1,5 @@
Object.keys(localStorage).forEach(function(key) {
if (/^global-alert-/.test(key)) {
document.documentElement.setAttribute('data-global-alert', 'closed');
}
});

View File

@ -2,16 +2,19 @@ var announcement = document.getElementById('announcement');
if (announcement !== null) {
if (localStorage.getItem('announcement') === null ) {
announcement.classList.remove('d-none');
}
announcement.addEventListener('closed.bs.alert', () => {
localStorage.setItem('announcement', 'closed');
var id = announcement.dataset.id;
Object.keys(localStorage).forEach(function(key) {
if (/^global-alert-/.test(key)) {
if (key !== id ) {
localStorage.removeItem(key);
document.documentElement.removeAttribute('data-global-alert');
}
}
});
}
announcement.addEventListener('closed.bs.alert', () => {
localStorage.setItem(id, 'closed');
});
}