Commit fd4ceea9 authored by Jakob Moser's avatar Jakob Moser
Browse files

Move exercise card methods to separate file

parent 58bc9141
Loading
Loading
Loading
Loading
+50 −0
Changes for static/js/exercises.cards.mjs: 50 added lines, 0 removed lines.
Original line number Diff line number Diff line
/** API to create cards for exercises */

/**
 * Changes the appearance of the given exercise card so it looks like it is solved
 * (this method does not care if the exercise is actually solved)
 * @param {HTMLElement} cardEl The .card element
 */
 function displayAsSolved(cardEl) {
    cardEl.classList.add("solved")
    setCardHoverTitle(cardEl, "Diese Aufgabe ist bereits gelöst, du kannst nicht mehr zu ihr springen.", false)
}

/**
 * Changes the appearance of the given exercise card so it looks like it is current
 * @param {HTMLElement} cardEl The .card element
 */
function displayAsCurrent(cardEl) {
    cardEl.classList.remove("collapsed")
    setCardHoverTitle(cardEl, "Du kannst nicht zur aktuellen Aufgabe springen.", false)
}

/**
 * Changes the appearance of the given exercise card so it looks like it is not current
 * @param {HTMLElement} cardEl The .card element
 */
function displayAsNonCurrent(cardEl) {
    cardEl.classList.add("collapsed")

    if(!cardEl.classList.contains("solved")) {
        setCardHoverTitle(cardEl, "Zu dieser Aufgabe springen", true)
    }
}

/**
 * Create a confirm and a reset button that can be appended to the actions section of
 * an exercise card.
 * @param {Function} manuallyConfirm Function to call to manually confirm this exercise
 * @returns List of buttons
 */
 function createExerciseCardActionButtons(manuallyConfirm) {
    const confirmButton = createElementWithClass("button", "primary")
    confirmButton.textContent = "Ich denke, ich bin fertig."
    confirmButton.onclick = ()=>manuallyConfirm()

    const resetButton = document.createElement("button")
    resetButton.textContent = "Aufgabe neu beginnen"
    resetButton.onclick = ()=>location.reload()

    return [confirmButton, resetButton]
}
+0 −49
Changes for static/js/yalikejazz.mjs: 0 added lines, 49 removed lines.
Original line number Diff line number Diff line
@@ -17,55 +17,6 @@ function findNextIncompleteExerciseIndex(currentExerciseIndex) {
    }
}

/**
 * Changes the appearance of the given exercise card so it looks like it is solved
 * (this method does not care if the exercise is actually solved)
 * @param {HTMLElement} cardEl The .card element
 */
function displayAsSolved(cardEl) {
    cardEl.classList.add("solved")
    setCardHoverTitle(cardEl, "Diese Aufgabe ist bereits gelöst, du kannst nicht mehr zu ihr springen.", false)
}

/**
 * Changes the appearance of the given exercise card so it looks like it is current
 * @param {HTMLElement} cardEl The .card element
 */
function displayAsCurrent(cardEl) {
    cardEl.classList.remove("collapsed")
    setCardHoverTitle(cardEl, "Du kannst nicht zur aktuellen Aufgabe springen.", false)
}

/**
 * Changes the appearance of the given exercise card so it looks like it is not current
 * @param {HTMLElement} cardEl The .card element
 */
function displayAsNonCurrent(cardEl) {
    cardEl.classList.add("collapsed")

    if(!cardEl.classList.contains("solved")) {
        setCardHoverTitle(cardEl, "Zu dieser Aufgabe springen", true)
    }
}

/**
 * Create a confirm and a reset button that can be appended to the actions section of
 * an exercise card.
 * @param {Function} manuallyConfirm Function to call to manually confirm this exercise
 * @returns List of buttons
 */
function createExerciseCardActionButtons(manuallyConfirm) {
    const confirmButton = createElementWithClass("button", "primary")
    confirmButton.textContent = "Ich denke, ich bin fertig."
    confirmButton.onclick = ()=>manuallyConfirm()

    const resetButton = document.createElement("button")
    resetButton.textContent = "Aufgabe neu beginnen"
    resetButton.onclick = ()=>location.reload()

    return [confirmButton, resetButton]
}

/**
 * Create a DOM card for the given exercise
 * @param {Exercise} exercise The exercise