aboutsummaryrefslogtreecommitdiff
path: root/assets/index.js
blob: 7905d9cac8f5d40849ed06a6b423dcecbcb3a573 (plain)
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
"use strict";
// Get the routeprefix by finding the '/' after the ID
let url = window.location.pathname;
let end = url.indexOf("/", "/server/".length + 1);
let routePrefix = url.substring(0, end);
console.log("routePrefix:", routePrefix);
let dels = document.querySelectorAll("form[action=\"/idea/delete/\"]");
for (let el of dels) {
    el.onsubmit = function (e) {
        e.preventDefault();
        if (confirm("are you sure?") === true) {
            el.submit();
        }
    };
}
let eels = document.querySelectorAll("button.edit");
for (let el of eels) {
    el.onclick = function () {
        let id = el.getAttribute("idea-id");
        location.href = routePrefix + "/idea/edit?id=" + id;
    };
}
let link = document.getElementById("link");
if (link !== null) {
    link.addEventListener("click", function () {
        navigator.clipboard.writeText(window.location.href);
        let old_text;
        if (link !== null) {
            old_text = link.innerHTML;
            link.innerHTML = "(copied)";
            link.classList.remove("copied");
        }
        setTimeout(function () {
            if (link !== null) {
                link.innerHTML = old_text;
                link.classList.add("copied");
            }
        }, 1000);
    });
}