Skip to content

Commit 219b5e6

Browse files
authored
Upgrade HTMX to version 2.0.3 (#198)
Signed-off-by: tdruez <[email protected]>
1 parent 0a45f0a commit 219b5e6

File tree

6 files changed

+45
-31
lines changed

6 files changed

+45
-31
lines changed

dejacode/static/js/dejacode_main.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,37 @@ function setupBackToTop() {
9494
});
9595
}
9696

97+
function setupHTMX() {
98+
// Triggered after new content has been swapped in
99+
document.body.addEventListener('htmx:afterSwap', function(evt) {
100+
const loadedContent = evt.detail.elt;
101+
102+
// Enables all tooltip and popover of the inserted HTML
103+
Array.from(loadedContent.querySelectorAll('[data-bs-toggle="tooltip"]')).forEach(element => {
104+
new bootstrap.Tooltip(element, { container: 'body' });
105+
});
106+
Array.from(loadedContent.querySelectorAll('[data-bs-toggle="popover"]')).forEach(element => {
107+
new bootstrap.Popover(element, { container: 'body' });
108+
});
109+
110+
// Disable the tab if a "disable-tab" CSS class if found in the loaded content
111+
if (loadedContent.querySelectorAll('.disable-tab').length > 0) {
112+
const tabPaneElement = loadedContent.closest('.tab-pane');
113+
// Find the corresponding button using its aria-controls attribute
114+
const buttonId = tabPaneElement.getAttribute('aria-labelledby');
115+
const button = document.querySelector(`#${buttonId}`);
116+
if (button) {
117+
button.disabled = true;
118+
}
119+
}
120+
});
121+
122+
// Triggered when an HTTP response error (non-200 or 300 response code) occurs
123+
document.addEventListener('htmx:responseError', function (event) {
124+
event.target.innerHTML = '<div class="h5 ms-4 text-danger">Error fetching</div>';
125+
});
126+
}
127+
97128
document.addEventListener('DOMContentLoaded', () => {
98129
NEXB = {};
99130
NEXB.client_data = JSON.parse(document.getElementById("client_data").textContent);
@@ -135,5 +166,5 @@ document.addEventListener('DOMContentLoaded', () => {
135166
setupPopovers();
136167
setupSelectionCheckboxes();
137168
setupBackToTop();
138-
169+
setupHTMX();
139170
});

dejacode/static/js/htmx-1.9.8.min.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

dejacode/static/js/htmx-2.0.3.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dje/templates/bootstrap_base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<script src="{% static 'bootstrap-5.3.2/js/bootstrap.bundle.min.js' %}" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
3131
<script src="{% static 'js/dejacode_main.js' %}" crossorigin="anonymous"></script>
3232
<script src="{% static 'js/bootstrap_theme_toggler.js' %}" crossorigin="anonymous"></script>
33-
<script defer src="{% static 'js/htmx-1.9.8.min.js' %}" integrity="sha384-rgjA7mptc2ETQqXoYC3/zJvkU7K/aP44Y+z7xQuJiVnB/422P/Ak+F/AqFR7E4Wr" crossorigin="anonymous"></script>
33+
<script src="{% static 'js/htmx-2.0.3.min.js' %}" integrity="sha384-0895/pl2MU10Hqc6jd4RvrthNlDiE9U1tWmX7WRESftEDRosgxNsQG/Ze9YMRzHq" crossorigin="anonymous"></script>
3434
{% include 'bootstrap_base_js.html' %}
3535
{% block javascripts %}{% endblock %}
3636
</body>

dje/templates/tabs/tab_async_loader.html

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,4 @@
22
<div class="h5 ms-4">
33
<i class="fas fa-spinner fa-spin"></i> Fetching {{ values.tab_object_name }}...
44
</div>
5-
</div>
6-
7-
<script>
8-
document.body.addEventListener('htmx:afterSwap', function(evt) {
9-
const loadedContent = evt.detail.elt;
10-
11-
// Enables all tooltip and popover of the inserted HTML
12-
Array.from(loadedContent.querySelectorAll('[data-bs-toggle="tooltip"]')).forEach(element => {
13-
new bootstrap.Tooltip(element, { container: 'body' });
14-
});
15-
Array.from(loadedContent.querySelectorAll('[data-bs-toggle="popover"]')).forEach(element => {
16-
new bootstrap.Popover(element, { container: 'body' });
17-
});
18-
19-
// Disable the tab if a "disable-tab" CSS class if found in the loaded content
20-
if (loadedContent.querySelectorAll('.disable-tab').length > 0) {
21-
const tabPaneElement = loadedContent.closest('.tab-pane');
22-
// Find the corresponding button using its aria-controls attribute
23-
const buttonId = tabPaneElement.getAttribute('aria-labelledby');
24-
const button = document.querySelector(`#${buttonId}`);
25-
if (button) {
26-
button.disabled = true;
27-
}
28-
}
29-
30-
});
31-
</script>
5+
</div>

product_portfolio/templates/product_portfolio/tabs/tab_inventory.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,16 @@
239239
{% endif %}
240240
{% endfor %}
241241
{% empty %}
242-
<tr><td colspan="100">No results.</td></tr>
242+
<tr>
243+
<td colspan="100">
244+
No results.
245+
{% if filter_productcomponent.is_active %}
246+
<a href="#" hx-get="{{ request.path }}?all=true#{{ tab_id }}" hx-target="{{ tab_id_html }}">
247+
Clear search and filters
248+
</a>
249+
{% endif %}
250+
</td>
251+
</tr>
243252
{% endfor %}
244253
</tbody>
245254
</table>

0 commit comments

Comments
 (0)