aboutsummaryrefslogtreecommitdiff
path: root/src/js/notification.js
blob: 7f368959e9d7695c809e0d9075796538f2fe8a46 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
let waiting_timer = undefined;
let notif_queue = [];

function notif(notif_c) {
    let notification_area = document.querySelector(".statusline .notification-area");

    if ((notification_area.querySelector(".notification") === null) && (waiting_timer === undefined)) {
        // This is just so no notifications will be played and disappears while the full screen landscape warning is in the way.
        if( (screen.availHeight > screen.availWidth) && (!document.body.classList.contains("ignore-landscape-warning"))){
            waiting_timer = setInterval(() => {
                if( (screen.availHeight < screen.availWidth) || (document.body.classList.contains("ignore-landscape-warning"))){
                    clearInterval(waiting_timer);
                    waiting_timer = undefined;
                    notif(notif_queue.pop());
                }
            }, 1000);
            notif_queue.push(notif_c);
            return;
        }

        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]);
}