Debian Codegraph @

test/manual/upgrade/app/static/js/app.js

raw symbols SCIP
1 /**
2 * Main application JS — htmx 2.x event handlers and utilities
3 */
4
5 // Request lifecycle
6 htmx.on('htmx:beforeRequest', function(e) {
7 NProgress.start();
8 });
9
10 htmx.on('htmx:afterRequest', function(e) {
11 NProgress.done();
12 });
13
14 htmx.on('htmx:afterSwap', function(e) {
15 // Re-initialize tooltips after swap
16 initTooltips(e.detail.elt);
17 });
18
19 htmx.on('htmx:afterSettle', function(e) {
20 // Focus first input in swapped content
21 const input = e.detail.elt.querySelector('input:not([type=hidden])');
22 if (input) input.focus();
23 });
24
25 // Error handling
26 htmx.on('htmx:responseError', function(e) {
27 showToast('Request failed: ' + e.detail.xhr.status, 'error');
28 });
29
30 htmx.on('htmx:sendError', function(e) {
31 showToast('Network error — please check your connection', 'error');
32 });
33
34 htmx.on('htmx:timeout', function(e) {
35 showToast('Request timed out', 'warning');
36 });
37
38 // Config modification
39 htmx.on('htmx:configRequest', function(e) {
40 // Add auth header to all requests
41 e.detail.headers['Authorization'] = 'Bearer ' + getAuthToken();
42 });
43
44 // History events
45 htmx.on('htmx:pushedIntoHistory', function(e) {
46 analytics.trackPageView(e.detail.path);
47 });
48
49 htmx.on('htmx:historyCacheMiss', function(e) {
50 console.warn('History cache miss for', e.detail.path);
51 });
52
53 htmx.on('htmx:historyRestore', function(e) {
54 reinitializePage();
55 });
56
57 // Validation
58 htmx.on('htmx:validation:validate', function(e) {
59 const form = e.detail.elt;
60 if (!customValidate(form)) {
61 e.preventDefault();
62 }
63 });
64
65 htmx.on('htmx:validation:halted', function(e) {
66 shakeElement(e.detail.elt);
67 });
68
69 // XHR progress (file uploads)
70 htmx.on('htmx:xhr:progress', function(e) {
71 const pct = (e.detail.loaded / e.detail.total) * 100;
72 updateProgressBar(pct);
73 });
74
75 // Load event
76 htmx.on('htmx:load', function(e) {
77 initComponents(e.detail.elt);
78 });
79
80 // DOM utility helpers using old htmx API
81 function showLoading(el) {
82 htmx.addClass(el, 'loading');
83 htmx.addClass(el, 'opacity-50');
84 }
85
86 function hideLoading(el) {
87 htmx.removeClass(el, 'loading');
88 htmx.removeClass(el, 'opacity-50');
89 }
90
91 function flashElement(el) {
92 htmx.addClass(el, 'flash');
93 setTimeout(function() {
94 htmx.removeClass(el, 'flash');
95 }, 1000);
96 }
97
98 function removeStale(el) {
99 const container = htmx.closest(el, '.container');
100 htmx.remove(el);
101 if (container && container.children.length === 0) {
102 htmx.remove(container);
103 }
104 }
105
106 function toggleActive(el) {
107 htmx.toggleClass(el, 'active');
108 }
109
110 // Extension registration
111 htmx.defineExtension('analytics', {
112 onEvent: function(name, evt) {
113 if (name === 'htmx:afterSwap') {
114 trackSwap(evt.detail);
115 }
116 }
117 });
118
119 // Config
120 htmx.config.defaultSwapStyle = 'innerHTML';
121 htmx.config.globalViewTransitions = true;
122 htmx.config.historyCacheSize = 30;
123 htmx.config.allowNestedOobSwaps = true;
124 htmx.config.scrollBehavior = 'smooth';
125 htmx.config.withCredentials = true;
126 htmx.config.wsReconnectDelay = 'full-jitter';