19 lines
824 B
JavaScript
19 lines
824 B
JavaScript
export default function NotificationsInit() {
|
|
const notificationsContainer = document.querySelector('.homegrade-notifications');
|
|
|
|
if (!notificationsContainer) return;
|
|
const notifications = notificationsContainer.querySelectorAll('.notification');
|
|
|
|
notifications.forEach((notification) => {
|
|
const notificationClose = notification.querySelector('.notification__close');
|
|
const notificationId = notification.getAttribute('data-notification-id');
|
|
console.log(notificationId);
|
|
|
|
notificationClose.addEventListener('click', () => {
|
|
notification.classList.add('notification--dismissed');
|
|
document.cookie = `${notificationId}=dismissed; path=/; max-age=30`;
|
|
// document.cookie = `${notificationId}=dismissed; path=/; max-age=${30 * 86400}`; // 86400 = 1 day
|
|
});
|
|
});
|
|
}
|