From 96a4492e6706b9802aec9744db247395f1bf0cbd Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Mon, 16 Jun 2025 21:09:31 -0500 Subject: fix linkable rules and support nesting --- html/js/linkableRules.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'html/js') 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"); } -- cgit v1.2.3