homegrade_theme_production/resources/js/notifications.js

19 lines
766 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');
const thirtyDays = 30 * 86400;
document.cookie = `${notificationId}=dismissed; path=/; max-age=${thirtyDays}`;
});
});
}