-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.html
196 lines (175 loc) · 6.66 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>HTMX playground & examples</title>
<link rel="icon" href="./favicon.png" type="image/png" />
<meta name="description" content="Learn HTMX with examples, and use the playground to write code in a backend-like environment, running entirely inside the browser. You can define endpoints within server.js and render your own templates. It will run a mock server that intercepts outgoing requests from HTMX.">
<script src="./src/main.js" type="module"></script>
<style>
body {
background-color: #222222;
margin: 0;
padding: 0;
width: 100vw;
height: 100vh;
color: white;
font-family: Arial, sans-serif;
font-size: 16px;
position: relative;
}
body.hide-popup #popup-top {
opacity: 0;
pointer-events: none;
}
#popup-top {
position: absolute;
inset: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background-color: #0007;
z-index: 100;
opacity: 1;
}
main#popup {
position: absolute;
margin: 2em auto;
width: calc(100vmin - 16px);
height: calc(100% - 8vmin);
flex-grow: 1;
background-color: #252525;
border-radius: 4px;
box-shadow: 0px 7px 32px #000;
overflow-y: auto;
line-height: 1.4;
font-family: system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,Segoe UI Emoji,Apple Color Emoji,Noto Color Emoji,sans-serif;
}
#popup article {
padding: 0 1em;
font-size: 20px;
}
#close-popup {
font-size: 1.2em;
padding: 0.4em 0.6em;
border-radius: 5px;
background-color: #0f06;
color: white;
border: none;
cursor: pointer;
margin: auto;
}
#close-popup:hover {
background-color: #0f07;
}
a {
color: #3391ff;
}
a:visited {
color: #7657ff;
}
h1 {
display: flex;
gap: 0.5em;
align-items: center;
}
code {
padding: 2.5px 5px;
border-radius: 6px;
font-size: 1em;
color: #ffbe85;
background: #101010;
}
blockquote {
border-left: 4px solid rgba(0,150,191,.67);
margin: 1.5em 0;
padding: 0.5em 1em;
font-style: italic;
}
blockquote cite {
font-style: normal;
}
blockquote > footer {
padding-top: 10px;
color: #b7b1a7;
}
blockquote > footer > cite::before {
content: "‒ ";
}
::-webkit-scrollbar {
background-color: #ffffff1e;
width: 8px;
height: 8px;
}
::-webkit-scrollbar-button {
display: none;
}
::-webkit-scrollbar-thumb {
background-color: rgba(255, 255, 255, 0.233);
border-radius: 1000px;
}
::-webkit-scrollbar-thumb:hover {
background-color: rgba(255, 255, 255, 0.308);
}
</style>
</head>
<body spellcheck="false">
<script>
if (localStorage.getItem('popup-shown') == 'true') {
document.body.classList.add('hide-popup');
}
</script>
<div id="popup-top">
<main id="popup">
<article>
<h1><img src="./logo_transparent_96.png" alt="HTMX Playground" width="64" height="64"> HTMX playground with examples</h1>
<blockquote cite="https://news.ycombinator.com/item?id=38906989">
"Finally a way to use HTMX as a SPA framework"
<footer>
<cite>Hackernews commenter</cite>
</footer>
</blockquote>
<p>
HTMX Playground is a simple code sandbox for playing around with HTMX. No setup needed!
</p>
<div style="text-align: center;">
<button id="close-popup" onclick="window.closePopup()">Go to playground ↪</button>
</div>
<p>
Check out the examples! I've adapted them from the original <a href="https://htmx.org/examples/">htmx.org examples</a>.
</p>
<p>
It allows you to write code in a backend-like environment, running entirely inside the browser. You can define endpoints within server.js and render your own templates. It will run a mock server that intercepts outgoing requests from HTMX. The request handling and templating engine should be very familiar to people who use Django. In principle, this project isn't specific to HTMX, so you are free to try out other libraries as well.
</p>
<h2>Saving & sharing</h2>
<ol>
<li>Press "Copy as JSON" in the top right.</li>
<li>Upload the contents as a Gist, and enter the raw URL in "Load Playground"</li>
<li>The URL on this page will update, and can now be shared.</li>
</ol>
<p>
The code is available <a target="_blank" href="https://github.com/lassebomh/htmx-playground">on GitHub</a>.
</p>
<h2>Caveats</h2>
<ul>
<li>No page navigation</li>
<li>Limited mobile support</li>
</ul>
<p>
Additionally, <code>server.js</code> can be stateful (such as in the Click to Edit example), but any update to the state in the <code>on.get("/")</code> view will be lost. This is due to the fact that the initial page load is retrieved in a seperate iframe, before updating the on-screen iframe.
</p>
<h2>Libraries used</h2>
<ul>
<li>Svelte</li>
<li>Ace (code editor)</li>
<li>PollyJS (mock server)</li>
<li>Nunjucks (templating engine)</li>
</ul>
</article>
</main>
</div>
<div id="app"></div>
</body>
</html>