diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-06-16 21:09:31 -0500 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-08-20 15:57:20 +0200 |
| commit | 96a4492e6706b9802aec9744db247395f1bf0cbd (patch) | |
| tree | 12a656e600651f1d9ca55fa8d74b43244ca49fc8 /html/js/linkableRules.js | |
| parent | 06f7814237308d177eae1b3faba294197af9ae30 (diff) | |
| download | muhqs-game-96a4492e6706b9802aec9744db247395f1bf0cbd.tar.gz muhqs-game-96a4492e6706b9802aec9744db247395f1bf0cbd.zip | |
fix linkable rules and support nesting
Diffstat (limited to 'html/js/linkableRules.js')
| -rw-r--r-- | html/js/linkableRules.js | 14 |
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"); } |
