1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-05-25 11:50:17 +02:00

createSolutions

This commit is contained in:
Alexandre Senges 2023-08-15 10:42:43 +00:00
parent 6ade0b002d
commit 16d1beff00

View File

@ -13,7 +13,9 @@
// limitations under the License.
(function() {
let notes = document.querySelector("details");
const details = new Array(...document.querySelectorAll("details"));
let notes = details.find(details => details.getAttribute("solution") === null);
const solutions = details.filter(details => details.getAttribute("solution") !== null);
// Create an unattached DOM node for the code below.
if (!notes) {
notes = document.createElement("details");
@ -47,7 +49,7 @@
break;
case "inline-open":
popIn.classList.add("hidden");
notes.open = true;
notes.open = notes.getAttribute("solution") === null;
notes.classList.remove("hidden");
break;
case "inline-closed":
@ -87,15 +89,15 @@
});
document.querySelector(".left-buttons").append(popIn);
// Create speaker notes.
const createSpeakerNotes = () => {
notes.addEventListener("toggle", (event) => {
setState(notes.open ? "inline-open" : "inline-closed");
});
let summary = document.createElement("summary");
const summary = document.createElement("summary");
notes.insertBefore(summary, notes.firstChild);
let h4 = document.createElement("h4");
const h4 = document.createElement("h4");
h4.setAttribute("id", "speaker-notes");
h4.append("Speaker Notes");
h4.addEventListener("click", (event) => {
@ -104,6 +106,21 @@
window.location.hash = "#speaker-notes";
});
summary.append(h4);
};
const createSolutions = () => {
for(const solution of solutions) {
const summary = document.createElement("summary");
solution.insertBefore(summary, solution.firstChild);
const h4 = document.createElement("h4");
h4.append("Solution");
summary.append(h4);
}
};
createSpeakerNotes();
createSolutions();
// Create pop-out button.
let popOutLocation = new URL(window.location.href);