feat: changeable global alert + fix: cumulative layout shift
This commit is contained in:
5
assets/js/alert-init.js
Normal file
5
assets/js/alert-init.js
Normal file
@ -0,0 +1,5 @@
|
||||
Object.keys(localStorage).forEach(function(key) {
|
||||
if (/^global-alert-/.test(key)) {
|
||||
document.documentElement.setAttribute('data-global-alert', 'closed');
|
||||
}
|
||||
});
|
@ -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');
|
||||
});
|
||||
|
||||
}
|
Reference in New Issue
Block a user