From 70ec859dee61a77ac813c1bf1e6f8d928fd1c2b2 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 5 Oct 2025 20:55:26 +0300 Subject: fix(teachihng/upp-2025/w02): Load styles like any normal stylesheet The old approach using JS would cause CORS policy errors. Since the stylesheet is disabled by default, it won't ever be downloaded, unless you're on a machine_table page. But even if you try, it will fail because of the relative path, making sure you almost never download it. --- src/teaching/upp-2025/week02/machine_table.css | 80 ++++++++++++++++++++++++ src/teaching/upp-2025/week02/machine_table.js | 85 +------------------------- 2 files changed, 82 insertions(+), 83 deletions(-) create mode 100644 src/teaching/upp-2025/week02/machine_table.css (limited to 'src') diff --git a/src/teaching/upp-2025/week02/machine_table.css b/src/teaching/upp-2025/week02/machine_table.css new file mode 100644 index 0000000..fee8577 --- /dev/null +++ b/src/teaching/upp-2025/week02/machine_table.css @@ -0,0 +1,80 @@ +/* Reset */ +#worksheet table, +#worksheet tr, +#worksheet th, +#worksheet td { + background-color: initial; + border: initial; + padding: 0.1em; +} + +/* General styling */ +#worksheet th { + font-weight: normal; +} +#worksheet { + color: black; + background-color: white; + margin: 1em auto; + + /* Thanks https://stackoverflow.com/a/4407335/12036073 */ + + -webkit-touch-callout: none; /* iOS Safari */ + -webkit-user-select: none; /* Safari */ + -khtml-user-select: none; /* Konqueror HTML */ + -moz-user-select: none; /* Old versions of Firefox */ + -ms-user-select: none; /* Internet Explorer/Edge */ + user-select: none; +} + +#worksheet button { + border-radius: 0; + border-width: 2px; + width: 100%; +} +#worksheet button:hover, +#worksheet input[type="radio"]:hover, +#worksheet input[type="radio"] ~ label:hover { + cursor: pointer; +} + +/* Borders and colors */ +#worksheet td, #worksheet th { + border: 1px solid #c0c0c0; +} +#worksheet tr:first-of-type th, +#worksheet td:first-child, #worksheet th:first-child +{ + border-color: #6a6a6a; + background-color: #f1f1f1; +} +#worksheet tr:first-of-type th { + border-top: none; +} +#worksheet td:first-child, #worksheet th:first-child { + border-left: none; +} + +/* Spacing */ +#worksheet th:first-child { + min-width: 2.82em; + padding: 0.3em 0; +} +#worksheet td { + min-width: 8em; + padding: 0.3em 0.2em; +} + +#worksheet button { + margin: calc(-0.3em + 4px) 0; + padding: 0.2em; +} + +/* Execution */ +.selected { + background-color: yellow !important; +} +.error { + background-color: red !important; +} + diff --git a/src/teaching/upp-2025/week02/machine_table.js b/src/teaching/upp-2025/week02/machine_table.js index ec67ff8..99a0255 100644 --- a/src/teaching/upp-2025/week02/machine_table.js +++ b/src/teaching/upp-2025/week02/machine_table.js @@ -1,88 +1,7 @@ // Style // -var machineStyles = document.createElement("style"); -machineStyles.textContent = ` - /* Reset */ - #worksheet table, - #worksheet tr, - #worksheet th, - #worksheet td { - background-color: initial; - border: initial; - padding: 0.1em; - } - - /* General styling */ - #worksheet th { - font-weight: normal; - } - #worksheet { - color: black; - background-color: white; - margin: 1em auto; - - /* Thanks https://stackoverflow.com/a/4407335/12036073 */ - - -webkit-touch-callout: none; /* iOS Safari */ - -webkit-user-select: none; /* Safari */ - -khtml-user-select: none; /* Konqueror HTML */ - -moz-user-select: none; /* Old versions of Firefox */ - -ms-user-select: none; /* Internet Explorer/Edge */ - user-select: none; - } - - #worksheet button { - border-radius: 0; - border-width: 2px; - width: 100%; - } - #worksheet button:hover, - #worksheet input[type="radio"]:hover, - #worksheet input[type="radio"] ~ label:hover { - cursor: pointer; - } - - /* Borders and colors */ - #worksheet td, #worksheet th { - border: 1px solid #c0c0c0; - } - #worksheet tr:first-of-type th, - #worksheet td:first-child, #worksheet th:first-child - { - border-color: #6a6a6a; - background-color: #f1f1f1; - } - #worksheet tr:first-of-type th { - border-top: none; - } - #worksheet td:first-child, #worksheet th:first-child { - border-left: none; - } - - /* Spacing */ - #worksheet th:first-child { - min-width: 2.82em; - padding: 0.3em 0; - } - #worksheet td { - min-width: 8em; - padding: 0.3em 0.2em; - } - - #worksheet button { - margin: calc(-0.3em + 4px) 0; - padding: 0.2em; - } - - /* Execution */ - .selected { - background-color: yellow !important; - } - .error { - background-color: red !important; - } -`; -document.head.appendChild(machineStyles); +const machineStyles = document.getElementById("upp2025_w02"); +machineStyles.disabled = false; // Execution // -- cgit v1.3.1-26-gb76a