refactor: remove the script tag JS and use the new submitLanguageForm function instead

This commit is contained in:
Francisco
2026-01-06 15:32:29 -05:00
parent 1c48a4a94e
commit c9b1ed0bba
2 changed files with 2 additions and 18 deletions

View File

@@ -1,7 +1,7 @@
{% load i18n static %}
<li>
<button class="dropdown-item" type="button" data-language="{{ code }}">
<button class="dropdown-item" type="button" onclick="submitLanguageForm('{{ code }}')">
<img src="{% static path %}"
width="20"
alt="{% translate name %}"

View File

@@ -66,6 +66,7 @@
</script>
<script src="{% static 'node/masonry-layout/dist/masonry.pkgd.min.js' %}"></script>
<script src="{% static 'js/nutrition.js' %}"></script>
<script src="{% static 'js/language.js' %}"></script>
{% endcompress %}
{# this needs to be outside of the compress block! #}
@@ -218,23 +219,6 @@
{% language_select language %}
{% endfor %}
</form>
<script>
document.querySelectorAll('[data-language]').forEach(item => {
item.addEventListener('click', function(e) {
e.preventDefault();
const langCode = this.dataset.language;
if (langCode === '') {
// Delete cookie and reload
document.cookie = 'django_language=; path=/; max-age=0';
window.location.reload();
} else {
document.getElementById('language-input').value = langCode;
document.getElementById('language-form').submit();
}
});
});
</script>
<li>
<hr class="dropdown-divider"></hr>