Skip to content

Commit

Permalink
Upgrade HTMX to version 2.0.3 (#198)
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez authored Nov 18, 2024
1 parent 0a45f0a commit 219b5e6
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 31 deletions.
33 changes: 32 additions & 1 deletion dejacode/static/js/dejacode_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,37 @@ function setupBackToTop() {
});
}

function setupHTMX() {
// Triggered after new content has been swapped in
document.body.addEventListener('htmx:afterSwap', function(evt) {
const loadedContent = evt.detail.elt;

// Enables all tooltip and popover of the inserted HTML
Array.from(loadedContent.querySelectorAll('[data-bs-toggle="tooltip"]')).forEach(element => {
new bootstrap.Tooltip(element, { container: 'body' });
});
Array.from(loadedContent.querySelectorAll('[data-bs-toggle="popover"]')).forEach(element => {
new bootstrap.Popover(element, { container: 'body' });
});

// Disable the tab if a "disable-tab" CSS class if found in the loaded content
if (loadedContent.querySelectorAll('.disable-tab').length > 0) {
const tabPaneElement = loadedContent.closest('.tab-pane');
// Find the corresponding button using its aria-controls attribute
const buttonId = tabPaneElement.getAttribute('aria-labelledby');
const button = document.querySelector(`#${buttonId}`);
if (button) {
button.disabled = true;
}
}
});

// Triggered when an HTTP response error (non-200 or 300 response code) occurs
document.addEventListener('htmx:responseError', function (event) {
event.target.innerHTML = '<div class="h5 ms-4 text-danger">Error fetching</div>';
});
}

document.addEventListener('DOMContentLoaded', () => {
NEXB = {};
NEXB.client_data = JSON.parse(document.getElementById("client_data").textContent);
Expand Down Expand Up @@ -135,5 +166,5 @@ document.addEventListener('DOMContentLoaded', () => {
setupPopovers();
setupSelectionCheckboxes();
setupBackToTop();

setupHTMX();
});
1 change: 0 additions & 1 deletion dejacode/static/js/htmx-1.9.8.min.js

This file was deleted.

1 change: 1 addition & 0 deletions dejacode/static/js/htmx-2.0.3.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dje/templates/bootstrap_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<script src="{% static 'bootstrap-5.3.2/js/bootstrap.bundle.min.js' %}" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
<script src="{% static 'js/dejacode_main.js' %}" crossorigin="anonymous"></script>
<script src="{% static 'js/bootstrap_theme_toggler.js' %}" crossorigin="anonymous"></script>
<script defer src="{% static 'js/htmx-1.9.8.min.js' %}" integrity="sha384-rgjA7mptc2ETQqXoYC3/zJvkU7K/aP44Y+z7xQuJiVnB/422P/Ak+F/AqFR7E4Wr" crossorigin="anonymous"></script>
<script src="{% static 'js/htmx-2.0.3.min.js' %}" integrity="sha384-0895/pl2MU10Hqc6jd4RvrthNlDiE9U1tWmX7WRESftEDRosgxNsQG/Ze9YMRzHq" crossorigin="anonymous"></script>
{% include 'bootstrap_base_js.html' %}
{% block javascripts %}{% endblock %}
</body>
Expand Down
28 changes: 1 addition & 27 deletions dje/templates/tabs/tab_async_loader.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,4 @@
<div class="h5 ms-4">
<i class="fas fa-spinner fa-spin"></i> Fetching {{ values.tab_object_name }}...
</div>
</div>

<script>
document.body.addEventListener('htmx:afterSwap', function(evt) {
const loadedContent = evt.detail.elt;

// Enables all tooltip and popover of the inserted HTML
Array.from(loadedContent.querySelectorAll('[data-bs-toggle="tooltip"]')).forEach(element => {
new bootstrap.Tooltip(element, { container: 'body' });
});
Array.from(loadedContent.querySelectorAll('[data-bs-toggle="popover"]')).forEach(element => {
new bootstrap.Popover(element, { container: 'body' });
});

// Disable the tab if a "disable-tab" CSS class if found in the loaded content
if (loadedContent.querySelectorAll('.disable-tab').length > 0) {
const tabPaneElement = loadedContent.closest('.tab-pane');
// Find the corresponding button using its aria-controls attribute
const buttonId = tabPaneElement.getAttribute('aria-labelledby');
const button = document.querySelector(`#${buttonId}`);
if (button) {
button.disabled = true;
}
}

});
</script>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,16 @@
{% endif %}
{% endfor %}
{% empty %}
<tr><td colspan="100">No results.</td></tr>
<tr>
<td colspan="100">
No results.
{% if filter_productcomponent.is_active %}
<a href="#" hx-get="{{ request.path }}?all=true#{{ tab_id }}" hx-target="{{ tab_id_html }}">
Clear search and filters
</a>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
Expand Down

0 comments on commit 219b5e6

Please sign in to comment.