Use htmx.on

This commit is contained in:
ekzyis 2024-09-05 23:33:23 +02:00
parent 76bc50355a
commit 2e3e4f02b4
3 changed files with 5 additions and 5 deletions

View File

@ -13,10 +13,10 @@ templ Invoice(hash string, bolt11 string, msats int, expiresIn int, paid bool, r
@InvoiceStatus(hash, expiresIn, paid, redirectUrl) @InvoiceStatus(hash, expiresIn, paid, redirectUrl)
<div class="none" id="bolt11-data" bolt11-data={ templ.JSONString(bolt11) } hx-preserve></div> <div class="none" id="bolt11-data" bolt11-data={ templ.JSONString(bolt11) } hx-preserve></div>
<script type="text/javascript" id="bolt11-js" hx-preserve> <script type="text/javascript" id="bolt11-js" hx-preserve>
$("#close").addEventListener("click", function () { htmx.on("#close", "click", function () {
// abort in-flight polls and prevent new polls // abort in-flight polls and prevent new polls
htmx.trigger("#poll", "htmx:abort") htmx.trigger("#poll", "htmx:abort")
$("#poll").addEventListener("htmx:beforeRequest", e => e.preventDefault()) htmx.on("#poll", "htmx:beforeRequest", function (e) { e.preventDefault() })
}) })
</script> </script>
</div> </div>

View File

@ -13,7 +13,7 @@ templ Modal(component templ.Component) {
@component @component
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
$("#close").addEventListener("click", function () { htmx.on("#close", "click", function () {
$("#modal").removeAttribute("class") $("#modal").removeAttribute("class")
$("#modal").setAttribute("class", "hidden") $("#modal").setAttribute("class", "hidden")
$("#modal").innerHTML = "" $("#modal").innerHTML = ""

View File

@ -27,11 +27,11 @@ templ CopyButton(value string) {
<div class="none" id="copy-data" copy-data={ templ.JSONString(value) } hx-preserve></div> <div class="none" id="copy-data" copy-data={ templ.JSONString(value) } hx-preserve></div>
<script type="text/javascript" id="copy-js" hx-preserve> <script type="text/javascript" id="copy-js" hx-preserve>
var value = JSON.parse($("#copy-data").getAttribute("copy-data")) var value = JSON.parse($("#copy-data").getAttribute("copy-data"))
$("#copy").onclick = function () { htmx.on("#copy", "click", function () {
window.navigator.clipboard.writeText(value) window.navigator.clipboard.writeText(value)
$("#copy").textContent = "copied" $("#copy").textContent = "copied"
setTimeout(() => $("#copy").textContent = "copy", 1000) setTimeout(() => $("#copy").textContent = "copy", 1000)
} })
</script> </script>
} }