-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.templ
57 lines (52 loc) · 1.62 KB
/
app.templ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
templ App() {
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script defer src="https://unpkg.com/[email protected]"></script>
<link rel="stylesheet" href="/public/styles.css">
</head>
<body>
<button type="button">Some other button</button>
<button
id="submitButton"
hx-post="/button"
hx-target="body"
hx-swap="outerHTML"
type="submit">
Click me
</button>
@SetupListeners()
</body>
</html>
}
script SetupListeners() {
const submitButton = document.querySelector("#submitButton")
submitButton.addEventListener("click", function(event) {
submitButton.classList.add("closing")
});
submitButton.addEventListener("animationend", function(event) {
submitButton.remove();
});
document.body.addEventListener("htmx:beforeRequest", function(event) {
console.log("htmx:beforeRequest", event);
const button = document.querySelector("button");
button.disabled = true;
button.textContent = "Loading...";
});
document.body.addEventListener("htmx:afterRequest", function(event) {
console.log("htmx:afterRequest", event);
const button = document.querySelector("button");
button.disabled = false;
button.textContent = "Click me";
});
document.body.addEventListener("htmx:responseError", function(event) {
console.log("htmx:responseError", event);
const buttons = document.querySelector("button")
const button = document.querySelector("button")
button.disabled = false
button.textContent = "Click me"
});
}