1
0
mirror of https://github.com/lus/pasty.git synced 2023-08-10 21:13:09 +03:00
pasty/web/assets/js/notifications.js

24 lines
645 B
JavaScript

// element holds the notification containers DOM element
const element = document.getElementById("notifications");
// error shows an error notifications
export function error(message) {
create("error", message, 3000);
}
// success shows a success notifications
export function success(message) {
create("success", message, 3000);
}
// create creates a new notification
function create(type, message, duration) {
const node = document.createElement("div");
node.classList.add(type);
node.innerHTML = message;
element.appendChild(node);
setTimeout(function() {
element.removeChild(node);
}, duration);
}