ryanvilbrandt / comic_git

A statically-hosted web comic server core intended to be hosted on github.io. For help getting started, click the Wiki link above!
23 stars 7 forks source link

Only show transcripts language selector if >1 language exists #51

Closed shirgoldbird closed 3 years ago

shirgoldbird commented 3 years ago

It would be nice if the transcript language selector only appeared if there was >1 language available for the page. I put in some slightly hacky code to handle this.

comic.tpl:

{% if transcripts.keys()|length > 1 %}
    <td id="language-list">
        <label for="language-select">Languages</label>
        <select id="language-select" size="7">
            {% for language in transcripts.keys() %}
            <option>{{ language }}</option>
            {% endfor %}
        </select>
    </td>
{% endif %}

transcript.js:

export function init() {
    let languageList = document.getElementById("language-select");
    let transcriptList = document.getElementById("active-transcript");
    let transcripts = transcriptList.children;

    // handle having only one language
    if (!languageList) {
        transcripts[0].style.display = "block";
        return;
    }

Let me know your thoughts!