Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor navbar javascript #2106

Open
richardebeling opened this issue Jan 22, 2024 · 0 comments
Open

Refactor navbar javascript #2106

richardebeling opened this issue Jan 22, 2024 · 0 comments
Labels
[C] Frontend Focuses on frontend implementation [P] Minor Minor priority [T] Refactoring Existing parts should become faster, more readable, or in any other way better.

Comments

@richardebeling
Copy link
Member

Proposal from #2099: Refactor the javascript code that makes the language and staff-mode buttons spin on user click

Original text:

How do you feel about removing the javascript for this and replacing everything inside the li with

<form id="set-lang-form" method="post" action="{% url 'evaluation:set_lang' %}">
    {% csrf_token %}

    <div class="btn-group">
        {% for language_code, language_name in languages %}
            <button
                type="submit" name="language" value="{{ language_code }}"
                class="btn btn-sm{% if current_language == language_code %} active{% endif %}"
                data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{ language_name }}"
            >
                <span>{{ language_code|upper }}</span>
            </button>
        {% endfor %}
    </div>
</form>

<script type="text/javascript" defer nonce="{{ request.csp_nonce }}">
    document.getElementById("set-lang-form").addEventListener("submit", event => {
        setSpinnerIcon(event.submitter.querySelector("span"));
    });
</script>

This also needs a change in setSpinnerIcon to something like

function setSpinnerIcon(element) {
    if (typeof element === "string" || element instanceof String)
        element = document.getElementById(element);
    element.innerHTML = "";
    element.className = "fas fa-spinner fa-spin";  // clears all other classes
}

Originally posted by @niklasmohrin in #2099 (comment)

@janno42 janno42 added [C] Frontend Focuses on frontend implementation [P] Minor Minor priority [T] Refactoring Existing parts should become faster, more readable, or in any other way better. labels Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C] Frontend Focuses on frontend implementation [P] Minor Minor priority [T] Refactoring Existing parts should become faster, more readable, or in any other way better.
Development

No branches or pull requests

2 participants