Added course's notes
This commit is contained in:
1 parent
e07993262c
commit
dcd2c072ae
191 files changed
+42866
-12
No files matched your search
@@ -0,0 +1,180 @@
|
||||
/* quiz — tick-box self-checks: options, per-option explanations, score bar
|
||||
*
|
||||
* The card borrows .exo's frame so a quiz and an exercise look related.
|
||||
* Green and red are reserved for the verdict: nothing else on the page uses
|
||||
* them, so a colour here always means "this answer was judged".
|
||||
*/
|
||||
|
||||
.quiz {
|
||||
--quiz-ok: #1a7f5a;
|
||||
--quiz-bad: #a3324a;
|
||||
--quiz-ink: #5a6879;
|
||||
|
||||
margin: 1.4rem 0;
|
||||
padding: 0.7rem 1rem 0.85rem;
|
||||
border: 1px solid color-mix(in srgb, var(--calc-notecolor, #B45309) 35%, transparent);
|
||||
border-left: 3px solid var(--calc-notecolor, #B45309);
|
||||
border-radius: 0.35rem;
|
||||
scroll-margin-top: 5rem;
|
||||
}
|
||||
|
||||
/* keep wide content inside the card, as in .calc and .exo */
|
||||
.quiz mjx-container[display="true"],
|
||||
.quiz .katex-display {
|
||||
max-width: 100%;
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
padding-bottom: 0.35em;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
justify-content: safe center;
|
||||
}
|
||||
.quiz .math.display { display: block; max-width: 100%; }
|
||||
.quiz :is(pre, table) { max-width: 100%; overflow-x: auto; }
|
||||
.quiz img, .quiz svg { max-width: 100%; }
|
||||
|
||||
.quiz-head { margin: 0 0 0.45rem; }
|
||||
.quiz-head strong { color: var(--calc-notecolor, #B45309); }
|
||||
|
||||
.quiz-tip {
|
||||
margin: 0 0 0.7rem;
|
||||
font-size: 0.82rem;
|
||||
color: var(--quiz-ink);
|
||||
}
|
||||
|
||||
/* ---- questions ------------------------------------------------------ */
|
||||
|
||||
.quiz-q + .quiz-q {
|
||||
margin-top: 1.1rem;
|
||||
padding-top: 0.9rem;
|
||||
border-top: 1px dashed color-mix(in srgb, var(--calc-notecolor, #B45309) 30%, transparent);
|
||||
}
|
||||
.quiz-q-head { margin: 0 0 0.35rem; font-size: 0.9em; }
|
||||
|
||||
/* ---- options -------------------------------------------------------- */
|
||||
|
||||
.quiz-opts {
|
||||
list-style: none;
|
||||
margin: 0.55rem 0 0;
|
||||
padding: 0;
|
||||
}
|
||||
.quiz-opt {
|
||||
margin: 0;
|
||||
padding: 0.22rem 0.4rem;
|
||||
border-radius: 0.25rem;
|
||||
border-left: 2px solid transparent;
|
||||
}
|
||||
.quiz-opt + .quiz-opt { margin-top: 0.15rem; }
|
||||
|
||||
/* the whole row is the click target, so a long formula is still easy to tick */
|
||||
.quiz-label {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 0.55rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
.quiz-box {
|
||||
flex: 0 0 auto;
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
margin: 0;
|
||||
/* baseline-align the box with the first line of the option text */
|
||||
transform: translateY(0.15rem);
|
||||
accent-color: var(--calc-notecolor, #B45309);
|
||||
cursor: pointer;
|
||||
}
|
||||
.quiz-opt-text { min-width: 0; }
|
||||
.quiz-opt-text > :first-child { margin-top: 0; }
|
||||
.quiz-opt-text > :last-child { margin-bottom: 0; }
|
||||
|
||||
/* judged options */
|
||||
.quiz-opt.quiz-ok {
|
||||
background: color-mix(in srgb, var(--quiz-ok) 8%, transparent);
|
||||
border-left-color: var(--quiz-ok);
|
||||
}
|
||||
.quiz-opt.quiz-bad {
|
||||
background: color-mix(in srgb, var(--quiz-bad) 8%, transparent);
|
||||
border-left-color: var(--quiz-bad);
|
||||
}
|
||||
|
||||
/* ---- explanations --------------------------------------------------- */
|
||||
|
||||
.quiz-why {
|
||||
margin: 0.35rem 0 0.15rem 1.55rem;
|
||||
padding: 0.3rem 0 0.3rem 0.7rem;
|
||||
border-left: 2px solid var(--quiz-bad);
|
||||
font-size: 0.88rem;
|
||||
}
|
||||
.quiz-why > :first-child { margin-top: 0; }
|
||||
.quiz-why > :last-child { margin-bottom: 0; }
|
||||
|
||||
.quiz-why-q {
|
||||
margin-left: 0;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
/* ---- verdict and bar ------------------------------------------------ */
|
||||
|
||||
.quiz-verdict {
|
||||
margin: 0.5rem 0 0;
|
||||
font-size: 0.85rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
.quiz-verdict.quiz-ok { color: var(--quiz-ok); }
|
||||
.quiz-verdict.quiz-bad { color: var(--quiz-bad); }
|
||||
|
||||
.quiz-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.6rem;
|
||||
flex-wrap: wrap;
|
||||
margin-top: 1rem;
|
||||
padding-top: 0.7rem;
|
||||
border-top: 1px solid color-mix(in srgb, var(--calc-notecolor, #B45309) 25%, transparent);
|
||||
}
|
||||
.quiz-bar button {
|
||||
font: inherit;
|
||||
font-size: 0.84rem;
|
||||
padding: 0.2rem 0.85rem;
|
||||
cursor: pointer;
|
||||
border: 1px solid color-mix(in srgb, var(--calc-notecolor, #B45309) 45%, transparent);
|
||||
border-radius: 999px;
|
||||
background: transparent;
|
||||
color: var(--calc-notecolor, #B45309);
|
||||
}
|
||||
.quiz-bar button:hover {
|
||||
background: color-mix(in srgb, var(--calc-notecolor, #B45309) 10%, transparent);
|
||||
}
|
||||
.quiz-bar button.quiz-reset {
|
||||
border-color: color-mix(in srgb, var(--quiz-ink) 40%, transparent);
|
||||
color: var(--quiz-ink);
|
||||
}
|
||||
.quiz-bar button.quiz-reset:hover {
|
||||
background: color-mix(in srgb, var(--quiz-ink) 10%, transparent);
|
||||
}
|
||||
.quiz-score {
|
||||
font-size: 0.84rem;
|
||||
color: var(--quiz-ink);
|
||||
}
|
||||
.quiz-score b { color: var(--calc-notecolor, #B45309); font-weight: 600; }
|
||||
|
||||
/* ---- dark theme ----------------------------------------------------- */
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.quiz {
|
||||
--quiz-ok: #4cb08a;
|
||||
--quiz-bad: #e2798f;
|
||||
--quiz-ink: #8b98a8;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- print ----------------------------------------------------------
|
||||
* Printing the HTML is a fallback (the pdf format is the real print path).
|
||||
* A printed quiz is one to fill in with a pen: the bar goes, the boxes stay
|
||||
* empty, and anything already revealed on screen is kept so a checked quiz
|
||||
* prints as it looks.
|
||||
*/
|
||||
@media print {
|
||||
.quiz-bar { display: none; }
|
||||
.quiz-opt.quiz-ok, .quiz-opt.quiz-bad { background: none; }
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
// quiz — judge the tick boxes of one quiz, explain what went wrong
|
||||
//
|
||||
// Every label the reader sees is written into the markup by quiz.lua, so the
|
||||
// wording follows the book's language and nothing is translated twice. A
|
||||
// quiz carries:
|
||||
// data-quiz-score "{n} of {m} questions correct" ({n}/{m} substituted)
|
||||
// data-quiz-right verdict of a question answered correctly
|
||||
// data-quiz-wrong verdict of a question answered wrongly
|
||||
//
|
||||
// A question is right only when every one of its options is in the right
|
||||
// state: ticked when true, left empty when false. That is the "multiple
|
||||
// true/false" rule of the exam, and it is why a half-ticked question counts
|
||||
// as wrong.
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
function options(quiz) {
|
||||
return quiz.querySelectorAll(".quiz-opt");
|
||||
}
|
||||
|
||||
function judge(quiz) {
|
||||
var questions = quiz.querySelectorAll(".quiz-q");
|
||||
var right = 0;
|
||||
|
||||
questions.forEach(function (q) {
|
||||
var ok = true;
|
||||
|
||||
q.querySelectorAll(".quiz-opt").forEach(function (opt) {
|
||||
var box = opt.querySelector(".quiz-box");
|
||||
if (!box) return;
|
||||
var want = opt.dataset.correct === "1";
|
||||
var hit = box.checked === want;
|
||||
|
||||
opt.classList.toggle("quiz-ok", hit);
|
||||
opt.classList.toggle("quiz-bad", !hit);
|
||||
|
||||
// the explanation of an option is for the reader who got it wrong
|
||||
var why = opt.querySelector(".quiz-why");
|
||||
if (why) why.hidden = hit;
|
||||
|
||||
if (!hit) ok = false;
|
||||
});
|
||||
|
||||
var verdict = q.querySelector(".quiz-verdict");
|
||||
if (verdict) {
|
||||
verdict.hidden = false;
|
||||
verdict.textContent = ok
|
||||
? (quiz.dataset.quizRight || "Correct")
|
||||
: (quiz.dataset.quizWrong || "Not quite");
|
||||
verdict.classList.toggle("quiz-ok", ok);
|
||||
verdict.classList.toggle("quiz-bad", !ok);
|
||||
}
|
||||
|
||||
// a question-level explanation backs up a wrong answer as a whole
|
||||
var qwhy = q.querySelector(".quiz-why-q");
|
||||
if (qwhy) qwhy.hidden = ok;
|
||||
|
||||
if (ok) right++;
|
||||
});
|
||||
|
||||
var score = quiz.querySelector(".quiz-score");
|
||||
if (score) {
|
||||
var template = quiz.dataset.quizScore || "{n}/{m}";
|
||||
score.innerHTML = "";
|
||||
// built as nodes, not markup: the template comes from metadata
|
||||
var parts = template.split(/\{n\}|\{m\}/);
|
||||
var values = [];
|
||||
(template.match(/\{n\}|\{m\}/g) || []).forEach(function (token) {
|
||||
values.push(token === "{n}" ? right : questions.length);
|
||||
});
|
||||
parts.forEach(function (text, i) {
|
||||
score.appendChild(document.createTextNode(text));
|
||||
if (i < values.length) {
|
||||
var b = document.createElement("b");
|
||||
b.textContent = String(values[i]);
|
||||
score.appendChild(b);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function reset(quiz) {
|
||||
options(quiz).forEach(function (opt) {
|
||||
var box = opt.querySelector(".quiz-box");
|
||||
if (box) box.checked = false;
|
||||
opt.classList.remove("quiz-ok", "quiz-bad");
|
||||
var why = opt.querySelector(".quiz-why");
|
||||
if (why) why.hidden = true;
|
||||
});
|
||||
quiz.querySelectorAll(".quiz-verdict").forEach(function (v) {
|
||||
v.hidden = true;
|
||||
v.textContent = "";
|
||||
v.classList.remove("quiz-ok", "quiz-bad");
|
||||
});
|
||||
quiz.querySelectorAll(".quiz-why-q").forEach(function (w) { w.hidden = true; });
|
||||
var score = quiz.querySelector(".quiz-score");
|
||||
if (score) score.textContent = "";
|
||||
}
|
||||
|
||||
document.addEventListener("click", function (event) {
|
||||
var target = event.target;
|
||||
if (!target.closest) return;
|
||||
|
||||
var check = target.closest(".quiz .quiz-check");
|
||||
if (check) {
|
||||
judge(check.closest(".quiz"));
|
||||
return;
|
||||
}
|
||||
var again = target.closest(".quiz .quiz-reset");
|
||||
if (again) {
|
||||
reset(again.closest(".quiz"));
|
||||
}
|
||||
});
|
||||
|
||||
// re-ticking a box after checking clears that row's verdict, so a stale
|
||||
// green or red never sits next to a box the reader has just changed
|
||||
document.addEventListener("change", function (event) {
|
||||
var box = event.target;
|
||||
if (!box.closest || !box.classList || !box.classList.contains("quiz-box")) return;
|
||||
var opt = box.closest(".quiz-opt");
|
||||
if (!opt) return;
|
||||
opt.classList.remove("quiz-ok", "quiz-bad");
|
||||
var why = opt.querySelector(".quiz-why");
|
||||
if (why) why.hidden = true;
|
||||
});
|
||||
})();
|
||||
Reference in new issue
Block a user