-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
281 lines (246 loc) · 6.55 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>HTMX Demo</title>
<script src="https://unpkg.com/htmx.org"></script>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
padding: 20px;
}
header,
footer {
text-align: center;
margin-bottom: 20px;
}
.example {
margin-bottom: 20px;
padding: 15px;
background-color: #f9f9f9;
border: 1px solid #ddd;
}
.example h2 {
font-size: 1.2em;
margin-top: 0;
}
hr {
margin: 20px 0;
}
</style>
</head>
<body>
<header>
<h1>HTMX Demo Page</h1>
<h3>* - examples with console output</h3>
</header>
<!-- Joke Loader -->
<div class="example">
<h2>Joke Loader</h2>
<div hx-get="https://v2.jokeapi.dev/joke/Any?format=txt&safe-mode">
Load Jokes
</div>
</div>
<hr />
<!-- AJAX Button -->
<div class="example">
<h2>AJAX Button with replace</h2>
<button hx-get="https://dummyjson.com/todos/1" hx-swap="outerHTML">
Click Me
</button>
</div>
<hr />
<!-- Prompt -->
<div class="example">
<h2>Prompt</h2>
<button
hx-delete="/account"
hx-prompt="Enter your account name to confirm deletion"
>
Delete My Account
</button>
</div>
<hr />
<!-- Custom Header -->
<div class="example">
<h2>Custom Header *</h2>
<button hx-get="/data" hx-headers='{"X-Custom-Header": "customValue"}'>
Fetch Data with Custom Header
</button>
</div>
<hr />
<!-- htmx Events -->
<div class="example">
<h2>htmx Events</h2>
<p>note: enable throttling in Network tab</p>
<!-- <script>
document.body.addEventListener('htmx:afterRequest', function (event) {
alert('Request completed!');
});
</script> -->
<button hx-get="https://dummyjson.com/todos/1">Get Data</button>
</div>
<hr />
<!-- Mouse Enter Trigger -->
<div class="example">
<h2>Mouse Enter Trigger *</h2>
<div hx-post="/mouse_entered" hx-trigger="mouseenter">
[Here Mouse, Mouse!]
</div>
<br />
<div hx-post="/mouse_entered" hx-trigger="mouseenter once">
[Here Mouse, Mouse! (once)]
</div>
</div>
<hr />
<!-- Live Search -->
<div class="example">
<h2>Live Search</h2>
<input
type="text"
name="q"
hx-get="https://dummyjson.com/posts/search"
hx-trigger="keyup delay:500ms changed"
hx-target="#search-results"
placeholder="Search..."
/>
<div id="search-results"></div>
</div>
<hr />
<!-- Control Click Example -->
<div class="example">
<h2>Control Click *</h2>
<div hx-get="/clicked" hx-trigger="click[ctrlKey]">Control Click Me</div>
</div>
<hr />
<!-- Polling -->
<div class="example">
<h2>Polling Every 2 Seconds *</h2>
<!-- <div hx-get="/news" hx-trigger="every 2s">
News updates every 2 seconds
</div> -->
</div>
<hr />
<!-- Delayed Click with Spinner -->
<div class="example">
<h2>Delayed Click with Spinner</h2>
<p>note: enable throttling in Network tab</p>
<button hx-get="https://dummyjson.com/recipes/1">
Click Me!
<img
class="htmx-indicator"
src="/img/spinning-circles.svg"
alt="Loading..."
/>
</button>
</div>
<hr />
<!-- Indicator Button -->
<div class="example">
<h2>Button with Custom GIF Indicator</h2>
<p>note: enable throttling in Network tab</p>
<button
hx-get="https://dummyjson.com/recipes/1"
hx-indicator="#indicator"
>
Click Me 2!
</button>
<img
id="indicator"
class="htmx-indicator"
style="width: 30px; height: 30px"
src="/img/spinner.gif"
alt="Loading..."
/>
</div>
<hr />
<!-- Request Cancelation -->
<div class="example">
<h2>Request Cancelation *</h2>
<p>note: enable throttling in Network tab</p>
<button id="request-button" hx-post="/example">Issue Request</button>
<button onclick="htmx.trigger('#request-button', 'htmx:abort')">
Cancel Request
</button>
</div>
<!-- Form Validation -->
<div class="example">
<h2>Form with Validation *</h2>
<form hx-post="/store">
<input
id="title"
name="title"
type="text"
hx-post="/validate"
hx-trigger="change"
placeholder="Enter title"
/>
<button type="submit">Submit</button>
</form>
<form hx-post="/store">
<input
id="title"
name="title"
type="text"
hx-post="/validate"
hx-trigger="change"
hx-sync="closest form:abort"
/>
<button type="submit">Submit</button>
</form>
</div>
<hr />
<!-- Custom Form Validation Example -->
<div class="example">
<h2>Custom Validation Example</h2>
<form
title="Validation"
id="example-form"
hx-get="https://dummyjson.com/posts/1/comments"
>
<input
name="example"
onkeydown="this.setCustomValidity('')"
hx-on:htmx:validation:validate="if(this.value != 'foo') {
this.setCustomValidity('Please enter the value foo');
htmx.find('#example-form').reportValidity();
}"
placeholder="Type 'foo' to validate"
/>
</form>
</div>
<hr />
<!-- Delete Account with Confirmation -->
<div class="example">
<h2>Delete with Confirmation</h2>
<button
hx-delete="/account"
hx-confirm="Are you sure you wish to delete your account?"
>
Delete My Account
</button>
</div>
<hr />
<!-- HTMX Boost Link -->
<div class="example">
<h2>Boosted Link *</h2>
<div hx-boost="true">
<a href="/blog">Blog</a>
</div>
</div>
<hr />
<!-- Content Update with Morph -->
<div class="example">
<h2>Content Update with Morph</h2>
<button hx-post="/example" hx-swap="morph" hx-target="#content">
Update Content
</button>
<div id="content">Original Content</div>
</div>
<footer>
<p>© 2024 HTMX - Lviv JavaClub</p>
</footer>
</body>
</html>