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
|
<html lang="en">
<head>
<style>
div {
transition: all 1000ms ease-in;
}
.indicator {
opacity: 0;
}
.hx-show-indicator .indicator {
opacity: 100%;
}
</style>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
</head>
<body style="padding:20px;font-family: sans-serif">
<script src="../../node_modules/sinon/pkg/sinon.js"></script>
<script src="../../src/htmx.js"></script>
<script src="../util/util.js"></script>
<script src="../util/scratch_server.js"></script>
<script>
// this.server.respondWith("GET", "/test2", "Clicked!");
//
// make('<div hx-get="/test">dd</div>')
// htmx.logAll();
// var i = 1;
// this.server.respondWith("GET", "/test", function(xhr){
// xhr.respond(201, {}, "" + i++);
// });
//
// make('<div hx-get="/test" hx-trigger="load, every 5s">Init</div>');
let xhr;
htmx.on('htmx:beforeSend', function(evt) {
xhr = evt.detail.xhr;
});
</script>
<h2>Server Options</h2>
<button onclick="server.respond()">Server Respond</button>
<br/>
Autorespond: <input id="autorespond" type="checkbox" onclick="toggleAutoRespond()">
<br/>
<br/>
<em>Work Area</em>
<hr/>
<form id="whatever">
</form>
<input form="whatever">
<div id="work-area" hx-history-elt>
<a id="a1" hx-boost="true" href="#" target="">Asdf</a>
</div>
<button onclick="console.log(this, event)">Log It...</button>
<button hx-get="/whatever">
</button>
<script>
let requestCount = 0;
this.server.respondWith("GET", "/demo", function(xhr){
let randomStr = (Math.random() + 1).toString(36).substring(7);
xhr.respond(200, {}, "Request #" + requestCount++ + " : " + randomStr)
});
</script>
<button hx-get="/demo"
hx-target="next h1"
hx-swap="innerHTML transition:true">Issue Request</button>
<h1 id="h1">--</h1>
<style>
@keyframes fade-in {
from { opacity: 0; }
}
@keyframes fade-out {
to { opacity: 0; }
}
@keyframes slide-from-right {
from { transform: translateX(90px); }
}
@keyframes slide-to-left {
to { transform: translateX(-90px); }
}
.slide-it {
view-transition-name: slide-it;
}
::view-transition-old(slide-it) {
animation: 180ms cubic-bezier(0.4, 0, 1, 1) both fade-out,
600ms cubic-bezier(0.4, 0, 0.2, 1) both slide-to-left;
}
::view-transition-new(slide-it) {
animation: 420ms cubic-bezier(0, 0, 0.2, 1) 90ms both fade-in,
600ms cubic-bezier(0.4, 0, 0.2, 1) both slide-from-right;
}
</style>
<div class="slide-it">
<h1>Initial Content</h1>
<button hx-get="/new-content" hx-swap="innerHTML transition:true" hx-target="closest div">
Swap It!
</button>
</div>
<script>
var originalContent = htmx.find(".slide-it").innerHTML;
this.server.respondWith("GET", "/new-content", function(xhr){
xhr.respond(200, {}, "<h1>Initial Content</h1> <button hx-get='/original-content' hx-swap='innerHTML transition:true' hx-target='closest div'>Restore It! </button>")
});
this.server.respondWith("GET", "/original-content", function(xhr){
xhr.respond(200, {}, originalContent)
});
</script>
</body>
</html>
|