MediaWiki

MediaWiki:BibTest.js

From Illustrations in German Translations of Mark Twain's Works

Revision as of 22:11, 11 May 2026 by HMHTEST (talk | contribs)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* =========================
   STATE
========================= */

const activeTags = new Set();

/* =========================
   TAG FILTERING (GLOBAL)
========================= */


document.querySelectorAll(".tag").forEach(tag => {

    tag.addEventListener("click", () => {

        const value = tag.dataset.tag;

        if (activeTags.has(value)) {
            activeTags.delete(value);
        } else {
            activeTags.add(value);
        }

        filterEntries();
        syncTagUI();   // 

    });

});


function filterEntries() {

    document.querySelectorAll(".bib-entry").forEach(entry => {

        const entryTags = entry.dataset.tags.split(" ");

        const matches =
            [...activeTags].every(t => entryTags.includes(t));

        if (activeTags.size === 0 || matches) {
            entry.style.display = "block";
        } else {
            entry.style.display = "none";
        }

    });

}


/* =========================
   VIEW SWITCH (LIST / NETWORK)
========================= */

document.querySelectorAll(".view-btn").forEach(btn => {

    btn.addEventListener("click", () => {

        document.querySelectorAll(".view-btn")
            .forEach(b => b.classList.remove("active"));

        btn.classList.add("active");

        const view = btn.dataset.view;

        const listView = document.getElementById("listView");
        const networkView = document.getElementById("networkView");

        listView.style.display = (view === "list") ? "block" : "none";
        networkView.classList.toggle("hidden", view !== "network");

        if (view === "network") {
            buildNetwork();
        }

    });

});


/* =========================
   EXPAND ABSTRACTS
========================= */

document.querySelectorAll(".expand-btn").forEach(btn => {

    btn.addEventListener("click", () => {

        const abstract = btn.nextElementSibling;

        abstract.classList.toggle("hidden");

        btn.textContent =
            abstract.classList.contains("hidden")
                ? "Show Abstract"
                : "Hide Abstract";

    });

});



function syncTagUI() {

    document.querySelectorAll(".tag").forEach(tagEl => {

        const value = tagEl.dataset.tag;

        if (activeTags.has(value)) {
            tagEl.classList.add("active");
        } else {
            tagEl.classList.remove("active");
        }

    });

}