function addNotification(text='Sample notification', type=4) {
let container = document.querySelector('.notifications');
// Create notification element
let div = document.createElement('div');
div.classList.add('sniffle__notification');
div.onclick = function() {
if (div.parentNode) {
div.classList.add('hide');
setTimeout(function() {
container.removeChild(div);
}, 500);
}
};
// Create icon element and append to notification
let icon = document.createElement('span');
icon.classList.add('sniffle__notification-icon');
switch (type) {
case 1:
div.classList.add('success');
icon.innerHTML = '';
break;
case 2:
div.classList.add('critical');
icon.innerHTML = '';
break;
case 3:
div.classList.add('warning');
icon.innerHTML = '';
break;
default:
div.classList.add('info');
icon.innerHTML = '';
break;
}
div.appendChild(icon);
// Create text element and append to notification
let description = document.createElement('span');
description.classList.add('sniffle__notification-text');
description.innerHTML = text;
div.appendChild(description);
// Create span to show time remaining
let timer = document.createElement('span');
timer.classList.add('sniffle__notification-time');
div.appendChild(timer);
// Append notification to container
container.appendChild(div);
setTimeout(function() {
div.classList.add('show');
}, 100);
// Remove notification after 5 seconds
setTimeout(function() {
if (div.parentNode) {
div.classList.add('hide');
setTimeout(function() {
container.removeChild(div);
}, 500);
}
}, 5000);
}