diff options
Diffstat (limited to 'pkgs/simple/cgit-about-filter/cgit-about-filter.lua')
| -rw-r--r-- | pkgs/simple/cgit-about-filter/cgit-about-filter.lua | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/pkgs/simple/cgit-about-filter/cgit-about-filter.lua b/pkgs/simple/cgit-about-filter/cgit-about-filter.lua index 7b36226..453c067 100644 --- a/pkgs/simple/cgit-about-filter/cgit-about-filter.lua +++ b/pkgs/simple/cgit-about-filter/cgit-about-filter.lua @@ -228,24 +228,30 @@ local function slug(content) end -- Headings link to themselves, underlined on hover by cgit.css. Clicking --- the heading that is the #fragment removes the fragment again. Setting --- location.hash is what makes :target forget the heading; --- history.replaceState alone doesn't. +-- the heading that is the #fragment, or anywhere but on a link, removes the +-- fragment again, and with it the highlight. Setting location.hash is what +-- makes :target forget the heading; history.replaceState alone doesn't. local heading_links = [[ <style> div#summary a.anchor { color: inherit; } </style> <script> document.addEventListener("click", event => { - const link = event.target.closest("a.anchor"); - if (link && link.hash === location.hash && event.button === 0 && - !(event.ctrlKey || event.metaKey || event.shiftKey || event.altKey)) { + if (event.button !== 0 || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey || + !document.querySelector("div#summary :target") || !getSelection().isCollapsed) { + return; + } + const link = event.target.closest("a"); + if (link) { + if (!link.matches("a.anchor") || link.hash !== location.hash) { + return; + } event.preventDefault(); - const x = scrollX, y = scrollY; - location.hash = ""; - scrollTo(x, y); - history.replaceState(null, "", location.pathname + location.search); } + const x = scrollX, y = scrollY; + location.hash = ""; + scrollTo(x, y); + history.replaceState(null, "", location.pathname + location.search); }); </script> ]] |
