mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-10 13:52:21 +01:00
Add announcements app
This commit is contained in:
@ -0,0 +1,34 @@
|
||||
.announcement {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background: var(--primary-shade);
|
||||
color: var(--primary-contrast);
|
||||
text-align: center;
|
||||
padding: 0.5rem 1rem;
|
||||
}
|
||||
|
||||
.announcement .btn-close {
|
||||
color: var(--primary-contrast);
|
||||
}
|
||||
|
||||
.announcement p {
|
||||
display: inline;
|
||||
margin: 0;
|
||||
color: var(--primary-contrast);
|
||||
font-size: 0.9rem;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.announcement a {
|
||||
color: var(--primary-contrast);
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.announcement a:hover {
|
||||
color: var(--primary-contrast-hover);
|
||||
}
|
||||
|
||||
.announcement button {
|
||||
background-size: .6rem;
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
const ANNOUNCEMENT_COOKIE = "closed-announcements";
|
||||
|
||||
function safeGetCookie() {
|
||||
try {
|
||||
return getCookie(ANNOUNCEMENT_COOKIE);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function sanitizeAnnouncementsArray(closedAnnouncements) {
|
||||
if (closedAnnouncements === null || typeof closedAnnouncements !== 'string') {
|
||||
return [];
|
||||
}
|
||||
else {
|
||||
try {
|
||||
closedAnnouncements = JSON.parse(closedAnnouncements);
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
if (! Array.isArray(closedAnnouncements)) {
|
||||
closedAnnouncements = [];
|
||||
}
|
||||
|
||||
for (let i = 0; i < closedAnnouncements.length; i++) {
|
||||
if (!Number.isInteger(closedAnnouncements[i])) {
|
||||
closedAnnouncements.splice(i, 1);
|
||||
}
|
||||
}
|
||||
return closedAnnouncements;
|
||||
}
|
||||
}
|
||||
function close_announcement(announcementId) {
|
||||
let announcementElement = document.getElementById("announcement-" + announcementId);
|
||||
|
||||
if (announcementElement !== null) {
|
||||
announcementElement.remove();
|
||||
}
|
||||
|
||||
let closedAnnouncements = safeGetCookie();
|
||||
|
||||
if (closedAnnouncements === null) {
|
||||
closedAnnouncements = [];
|
||||
} else {
|
||||
closedAnnouncements = sanitizeAnnouncementsArray(closedAnnouncements);
|
||||
}
|
||||
|
||||
if (!closedAnnouncements.includes(announcementId)) {
|
||||
closedAnnouncements.push(announcementId);
|
||||
}
|
||||
|
||||
setListCookie(ANNOUNCEMENT_COOKIE, closedAnnouncements, 31);
|
||||
}
|
||||
Reference in New Issue
Block a user