fix: Attatch event listener to paste button on htmx load

This commit is contained in:
Evan Fiordeliso 2023-08-16 11:30:31 -04:00
parent 75b5c4160d
commit ffb35c3220
1 changed files with 20 additions and 10 deletions

View File

@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en" class="h-100">
<head>
<meta charset="UTF-8" />
@ -69,16 +69,26 @@
</div>
{{template "partials/footer" .}}
<script>
const pasteButton = document.getElementById("paste-button");
const urlField = document.getElementById("url");
pasteButton.addEventListener("click", async () => {
try {
const text = await navigator.clipboard.readText();
urlField.value = text;
} catch (error) {
toastr.error("Failed to paste url from clipboard.");
/**
* @param content {Element}
*/
function setupPaste(content) {
const pasteButton = content.querySelector("#paste-button");
const urlField = content.querySelector("#url");
if (pasteButton) {
pasteButton.addEventListener("click", async () => {
try {
const text = await navigator.clipboard.readText();
urlField.value = text;
} catch (error) {
toastr.error("Failed to paste url from clipboard.");
}
});
}
});
}
htmx.onLoad(setupPaste);
</script>
</body>
</html>