fix: Attatch event listener to paste button on htmx load
This commit is contained in:
parent
75b5c4160d
commit
ffb35c3220
|
@ -1,4 +1,4 @@
|
||||||
<!DOCTYPE html>
|
<!doctype html>
|
||||||
<html lang="en" class="h-100">
|
<html lang="en" class="h-100">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
|
@ -69,16 +69,26 @@
|
||||||
</div>
|
</div>
|
||||||
{{template "partials/footer" .}}
|
{{template "partials/footer" .}}
|
||||||
<script>
|
<script>
|
||||||
const pasteButton = document.getElementById("paste-button");
|
/**
|
||||||
const urlField = document.getElementById("url");
|
* @param content {Element}
|
||||||
pasteButton.addEventListener("click", async () => {
|
*/
|
||||||
try {
|
function setupPaste(content) {
|
||||||
const text = await navigator.clipboard.readText();
|
const pasteButton = content.querySelector("#paste-button");
|
||||||
urlField.value = text;
|
const urlField = content.querySelector("#url");
|
||||||
} catch (error) {
|
|
||||||
toastr.error("Failed to paste url from clipboard.");
|
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>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue