init commit (base extensions: notes)
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
// exo — hints unlock one by one; everything unfolds for printing
|
||||
(function () {
|
||||
// block opening a locked hint
|
||||
document.addEventListener("click", function (e) {
|
||||
var s = e.target.closest ? e.target.closest("details.exo-hint.exo-locked > summary") : null;
|
||||
if (s) e.preventDefault();
|
||||
});
|
||||
|
||||
// opening hint n unlocks hint n+1 (toggle doesn't bubble: use capture)
|
||||
document.addEventListener("toggle", function (e) {
|
||||
var d = e.target;
|
||||
if (!d.classList || !d.classList.contains("exo-hint") || !d.open) return;
|
||||
var next = d.nextElementSibling;
|
||||
while (next && !(next.tagName === "DETAILS" && next.classList.contains("exo-hint"))) {
|
||||
next = next.nextElementSibling;
|
||||
}
|
||||
if (next) next.classList.remove("exo-locked");
|
||||
}, true);
|
||||
|
||||
// print: open all hints/solutions, restore afterwards
|
||||
window.addEventListener("beforeprint", function () {
|
||||
document.querySelectorAll(".exo details").forEach(function (d) {
|
||||
d.dataset.exoWasOpen = d.open ? "1" : "0";
|
||||
d.open = true;
|
||||
});
|
||||
});
|
||||
window.addEventListener("afterprint", function () {
|
||||
document.querySelectorAll(".exo details").forEach(function (d) {
|
||||
d.open = d.dataset.exoWasOpen === "1";
|
||||
delete d.dataset.exoWasOpen;
|
||||
});
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user