Commit 0208761d authored by Jakob Moser's avatar Jakob Moser
Browse files

Move setDialogShown to different file

parent eaf55249
Loading
Loading
Loading
Loading

static/js/dialogs.mjs

0 → 100644
+17 −0
Original line number Diff line number Diff line
/**
 * Show (or hide) a dialog
 * @param {string} id The id of the dialog
 * @param {boolean} shown If the dialog should be shown or hidden
 */
export function setDialogShown(id, shown) {
    const DIALOG_SHOWN = "dialog-shown";
    const dialog = document.querySelector(`#${id}`);

    if (shown) {
        document.body.classList.add(DIALOG_SHOWN);
        dialog.classList.add(DIALOG_SHOWN);
    } else {
        dialog.classList.remove(DIALOG_SHOWN);
        document.body.classList.remove(DIALOG_SHOWN);
    }
}
+1 −18
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ import { createExerciseCard, displayAsSolved, displayAsNonCurrent, displayAsCurr
import { Exercise } from "./exercises.api.mjs"
import { isVmLoading, onCopyOrPasteHotkey, setAutoFocusEnabled } from "./jslinux.api.mjs"
import { findParent, waitFor } from "./util.mjs"
import { setDialogShown } from "./dialogs.mjs"

const testId = new URLSearchParams(location.search).get("id")
const currentTest = tests[testId]
@@ -130,24 +131,6 @@ function initActionLinks() {
    })
}

/**
 * Show (or hide) a dialog
 * @param {string} id The id of the dialog
 * @param {boolean} shown If the dialog should be shown or hidden
 */
function setDialogShown(id, shown) {
    const DIALOG_SHOWN = "dialog-shown"
    const dialog = document.querySelector(`#${id}`)

    if(shown) {
        document.body.classList.add(DIALOG_SHOWN)
        dialog.classList.add(DIALOG_SHOWN)
    } else {
        dialog.classList.remove(DIALOG_SHOWN)
        document.body.classList.remove(DIALOG_SHOWN)
    }
}

/**
 * Enables or disables all exercise action buttons
 * @param {boolean} enabled If all exercise action buttons should be enabled