diff options
Diffstat (limited to 'assets/index.js')
-rw-r--r-- | assets/index.js | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/assets/index.js b/assets/index.js index 6146c01..7905d9c 100644 --- a/assets/index.js +++ b/assets/index.js @@ -1,4 +1,9 @@ "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) { @@ -11,8 +16,25 @@ for (let el of dels) { let eels = document.querySelectorAll("button.edit"); for (let el of eels) { el.onclick = function () { - console.log("clicked"); - let title = el.getAttribute("data-title"); - location.href = "/idea/edit?t=" + title; + 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); + }); +} |