diff options
Diffstat (limited to 'assets/index.ts')
-rw-r--r-- | assets/index.ts | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/assets/index.ts b/assets/index.ts index 70b03b7..8081428 100644 --- a/assets/index.ts +++ b/assets/index.ts @@ -1,3 +1,9 @@ +// 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:NodeListOf<HTMLFormElement> = document.querySelectorAll("form[action=\"/idea/delete/\"]"); for (let el of dels) { el.onsubmit = function(e) { @@ -8,11 +14,29 @@ for (let el of dels) { }; } -let eels:NodeListOf<HTMLElement> = document.querySelectorAll("button.edit"); +let eels:NodeListOf<HTMLButtonElement> = 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: string; + 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); +}); +} |