1
0
mirror of https://github.com/lus/pasty.git synced 2023-08-10 21:13:09 +03:00
pasty/web/assets/js/modules/notifications.js
Lukas Schulte Pelkum 70c4392390
Improve the frontend (API v2 functionalities) (#18)
* Fix line number height issue

* Fix notification container position

* Remove line wrapping

* Switch to the new API

* Rework JS & implement paste editing

* Implement paste reports

* Document the report webhook
2021-07-23 23:39:37 +02:00

25 lines
813 B
JavaScript

import * as Animation from "./animation.js";
const ELEMENT = document.getElementById("notifications");
// Shows a success notification
export function success(message) {
create("success", message, 3000);
}
// Shows an error notification
export function error(message) {
create("error", message, 3000);
}
// Creates a new custom notification
function create(type, message, duration) {
const node = document.createElement("div");
node.classList.add(type);
Animation.animate(node, "animate__fadeInUp", "0.2s");
node.innerHTML = message;
ELEMENT.childNodes.forEach(child => Animation.animate(child, "animate__slideInUp", "0.2s"));
ELEMENT.appendChild(node);
setTimeout(() => Animation.animate(node, "animate__fadeOutUp", "0.2s", () => ELEMENT.removeChild(node)), duration);
}