diff options
author | Jakob Stendahl <jakob.stendahl@outlook.com> | 2021-02-06 14:10:00 +0100 |
---|---|---|
committer | Jakob Stendahl <jakob.stendahl@outlook.com> | 2021-02-06 14:10:00 +0100 |
commit | b07c2d6792174c9132679671ea7dae77c87349d9 (patch) | |
tree | 06c534166d24f3c426a7dff9aa1cbce2e1cfd639 /src/js/notification.js | |
parent | 34a24733ef7159105ab162f870b96e9649bc5c34 (diff) | |
download | hoverbit-ble-b07c2d6792174c9132679671ea7dae77c87349d9.tar.gz hoverbit-ble-b07c2d6792174c9132679671ea7dae77c87349d9.zip |
Use parcel, add features
Diffstat (limited to 'src/js/notification.js')
-rw-r--r-- | src/js/notification.js | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/js/notification.js b/src/js/notification.js new file mode 100644 index 0000000..c2eb14c --- /dev/null +++ b/src/js/notification.js @@ -0,0 +1,83 @@ +let notif_queue = []; + +function notif(notif_c) { + let notification_area = document.querySelector(".statusline .notification-area"); + + if (notification_area.querySelector(".notification") === null) { + let notif_elem = document.createElement("div"); + notif_elem.className = "notification"; + notif_elem.appendChild(notif_c[0]); + notif_elem.appendChild(notif_c[1]); + + notification_area.appendChild(notif_elem); + + setTimeout(() => { + notification_area.removeChild(notif_elem); + if (notif_queue.length > 0) { + notif(notif_queue.pop()); + } + }, 5000); + } else { + notif_queue.push(notif_c); + } +} + +export function notif_alert(alert_str) { + let div = document.createElement("div"); + div.className = "notification-content"; + + let text = document.createElement("p"); + text.innerHTML = alert_str; + div.appendChild(text); + + let icon = document.createElement("i"); + icon.className = "alert fas fa-exclamation-triangle"; + div.appendChild(icon); + + notif([icon, div]); +} + +export function notif_warn(alert_str) { + let div = document.createElement("div"); + div.className = "notification-content"; + + let text = document.createElement("p"); + text.innerHTML = alert_str; + div.appendChild(text); + + let icon = document.createElement("i"); + icon.className = "warning fas fa-exclamation-triangle"; + div.appendChild(icon); + + notif([icon, div]); +} + +export function notif_info(info_str) { + let div = document.createElement("div"); + div.className = "notification-content"; + + let text = document.createElement("p"); + text.innerHTML = info_str; + div.appendChild(text); + + let icon = document.createElement("i"); + icon.className = "info fas fa-info-circle"; + div.appendChild(icon); + + notif([icon, div]); +} + +export function notif_success(success_str) { + let div = document.createElement("div"); + div.className = "notification-content"; + + let text = document.createElement("p"); + text.innerHTML = success_str; + div.appendChild(text); + + let icon = document.createElement("i"); + icon.className = "success fas fa-check-circle"; + div.appendChild(icon); + + notif([icon, div]); +} |