aboutsummaryrefslogtreecommitdiff
path: root/html/js
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-06-16 21:09:31 -0500
committerFlorian Fischer <florian.fischer@muhq.space>2025-07-03 22:01:22 -0400
commit56dc7801d6e91e3df57f305a42c3d38ce0ae6e70 (patch)
treea28c32a5eb5a85907b8f83f49938cd5dd64af52d /html/js
parent2432c7cd45f8955e2dcd46a3c063052d09a085ab (diff)
downloadmuhqs-game-56dc7801d6e91e3df57f305a42c3d38ce0ae6e70.tar.gz
muhqs-game-56dc7801d6e91e3df57f305a42c3d38ce0ae6e70.zip
fix linkable rules and support nesting
Diffstat (limited to 'html/js')
-rw-r--r--html/js/linkableRules.js14
1 files changed, 11 insertions, 3 deletions
diff --git a/html/js/linkableRules.js b/html/js/linkableRules.js
index 82261a1e..b590aabe 100644
--- a/html/js/linkableRules.js
+++ b/html/js/linkableRules.js
@@ -21,24 +21,32 @@ through which recipients can access the Corresponding Source.
@licend The above is the entire license notice
for the JavaScript code in this page.
*/
+var highlightedRule;
function prepareLinkableRules() {
for (let e of document.querySelectorAll(".rule")) {
// Add class via js to ensure there is no wrong
// sense of functionality in browsers without js
e.classList.add("linkable-rule");
- // TODO: support nested lists
- e.onclick = function() {
+ e.onclick = function(event) {
if (e.matches(':hover') || e.matches(':active')) {
+ // Set background with JS for more control
+ if (highlightedRule) {
+ highlightedRule.classList.remove("highlighted");
+ }
+ highlightedRule = e;
+ e.classList.add("highlighted");
const origin = window.location.origin;
const path = window.location.pathname;
const anchor = e.id;
let url = origin + '/' + path + '#' + anchor;
navigator.clipboard.writeText(url);
- // document.getElementsByTagName("body")[0].focus();
+ // Stop the event handling for potential parent rules
+ event.stopPropagation();
}
}
}
}
window.onload = function() {
prepareLinkableRules();
+ console.log("loaded");
}