Define jQuery helper in head

This commit is contained in:
ekzyis 2024-09-05 23:20:07 +02:00
parent e4da49b215
commit 76bc50355a
4 changed files with 4 additions and 4 deletions

View File

@ -28,5 +28,9 @@ templ Head() {
if ctx.Value(c.EnvContextKey) == "development" {
<script defer src="/js/hotreload.js"></script>
}
<script type="text/javascript">
// helper functions
var $ = selector => document.querySelector(selector)
</script>
</head>
}

View File

@ -13,7 +13,6 @@ templ Invoice(hash string, bolt11 string, msats int, expiresIn int, paid bool, r
@InvoiceStatus(hash, expiresIn, paid, redirectUrl)
<div class="none" id="bolt11-data" bolt11-data={ templ.JSONString(bolt11) } hx-preserve></div>
<script type="text/javascript" id="bolt11-js" hx-preserve>
var $ = selector => document.querySelector(selector)
$("#close").addEventListener("click", function () {
// abort in-flight polls and prevent new polls
htmx.trigger("#poll", "htmx:abort")
@ -42,7 +41,6 @@ templ InvoiceStatus(hash string, expiresIn int, paid bool, redirectUrl templ.Saf
<!-- invoice is pending -->
<div class="font-mono my-1" id="countdown" countdown-data={ templ.JSONString(expiresIn) } hx-preserve></div>
<script type="text/javascript" id="countdown-js" hx-preserve>
var $ = selector => document.querySelector(selector)
var expiresIn = JSON.parse($("#countdown").getAttribute("countdown-data"))
function pad(num, places) {

View File

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

View File

@ -26,7 +26,6 @@ templ Qr(value string, href string) {
templ CopyButton(value string) {
<div class="none" id="copy-data" copy-data={ templ.JSONString(value) } hx-preserve></div>
<script type="text/javascript" id="copy-js" hx-preserve>
var $ = selector => document.querySelector(selector)
var value = JSON.parse($("#copy-data").getAttribute("copy-data"))
$("#copy").onclick = function () {
window.navigator.clipboard.writeText(value)