-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
85 lines (79 loc) · 2.84 KB
/
index.html
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://unpkg.com/[email protected]"></script>
<script src="dist/index.js"></script>
<title>Document</title>
</head>
<body>
<h1>Buttons</h1>
<p>
<label> Button 1
<button hx-get="/clicked" hx-swap="outerHTML" hx-ext="serverless">
Click!
</button>
</label>
</p>
<p>
<label> Button 2
<button hx-get="/clicked" hx-swap="outerHTML" hx-ext="serverless">
Click!
</button>
</label>
</p>
<p>
<!-- FORM POST -->
<form hx-post="/submitmail" hx-ext="serverless">
<label> Email
<input type="text" name="email_address">
</label>
<label> Button 2
<button type="submit">Go!</button>
</label>
</form>
<!-- FORM GET -->
<form hx-get="/submitmail" hx-ext="serverless">
<label> Email
<input type="text" name="email_address">
</label>
<label> Button 2
<button type="submit">Go!</button>
</label>
</form>
</p>
<p>
<button hx-get="/example" hx-target="next .counter" hx-trigger="load, click" hx-vals='js:{myVal: i++}' hx-ext="serverless">Click to Increment</button>
<span class="counter"></span>
</p>
<p>
<button hx-get="js:myFunc" hx-target="next .counter" hx-trigger="load, click" hx-vals='js:{myVal: j++}' hx-ext="serverless">Click to Increment</button>
<span class="counter"></span>
</p>
<script>
htmxServerless.handlers.set('/clicked', '<button hx-post="/clicked2" hx-swap="outerHTML" hx-ext="serverless">Click again!</button>')
htmxServerless.handlers.set('/clicked2', '<button hx-post="/clicked" hx-swap="outerHTML" hx-ext="serverless">Click!</button>');
// Form
htmxServerless.handlers.set('/submitmail', function(text, params, xhr){
if ( params?.email_address != '[email protected]' ) {
return this.outerHTML;
} else {
return "Thanks!"
}
});
// DIV
let i = 0;
htmxServerless.handlers.set('/example', function(text, params, xhr){
let status = params?.myVal < 10 ? "smaller or equals to" : "bigger than";
return `Value of "myVal" is: ${params?.myVal}, it is ${status} 10.`;
});
// Custom hander with js:myFunc()
let j = 0;
function myFunc(text, params, xhr){
let status = params?.myVal < 10 ? "smaller or equals to" : "bigger than";
return `Value of "myVal" is: ${params?.myVal}, it is ${status} 10.`;
}
</script>
</body>
</html>