-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
85 lines (62 loc) · 2.17 KB
/
app.ts
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
import htmx from 'htmx.org';
htmx.config.historyEnabled = true;
htmx.config.historyCacheSize = 10;
htmx.config.refreshOnHistoryMiss = false;
htmx.config.defaultSwapStyle = 'innerHTML';
htmx.config.defaultSwapDelay = 0;
htmx.config.defaultSettleDelay = 20;
htmx.config.includeIndicatorStyles = true;
htmx.config.indicatorClass = 'htmx-indicator';
htmx.config.requestClass = 'htmx-request';
htmx.config.settlingClass = 'htmx-settling';
htmx.config.swappingClass = 'htmx-swapping';
htmx.config.allowEval = true;
htmx.config.attributesToSettle = ["class", "style", "width", "height"];
htmx.config.withCredentials = false;
htmx.config.wsReconnectDelay = 'full-jitter';
htmx.config.disableSelector = "[hx-disable], [data-hx-disable]";
let headerElement = document.getElementById('header')!;
htmx.addClass(headerElement, 'myClass');
htmx.ajax('GET', '/example', '#myDiv');
htmx.closest(headerElement, 'div');
htmx.createEventSource = function (url) {
return new EventSource(url, {withCredentials: false});
}
htmx.createWebSocket = function (url) {
return new WebSocket(url, ['wss']);
};
htmx.defineExtension("silly", {
onEvent: function (name: string, evt: Event) {
console.log("Event " + name + " was triggered!", evt)
}
});
htmx.find("#my-div")
htmx.find(headerElement, "#another-div")
htmx.logAll();
htmx.logger = function (elt, event, data) {
if (console) {
console.log("INFO:", event, elt, data);
}
}
// add a click listener to the body
let myEventListener1 = htmx.on("click", function (evt) {
console.log(evt);
});
// add a click listener to the given div
let myEventListener2 = htmx.on("#my-div", "click", function (evt) {
console.log(evt);
});
// remove this click listener from the body
htmx.off("click", myEventListener1);
// remove this click listener from the given div
htmx.off("#my-div", "click", myEventListener2)
htmx.onLoad(function (elt) {
console.log(elt);
})
htmx.parseInterval("3s");
htmx.process(headerElement);
htmx.removeClass(headerElement, "myClass");
htmx.removeExtension("my-extension");
htmx.takeClass(headerElement, "selected");
htmx.toggleClass(headerElement, "selected");
htmx.trigger(headerElement, "myEvent", {answer: 42});