summaryrefslogtreecommitdiffstats
path: root/pkgs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-18 12:28:02 +0000
committertv <tv@krebsco.de>2026-11-18 13:30:00 +0100
commit93ef5771b6e2443dd787002d600a1ba715d901e7 (patch)
treee3f4079ce802b9dbe26d13c8278982f9891dac97 /pkgs
parentc1862d78f704f9c7f7cec19c8f0d03d632c11115 (diff)
cgit-about-filter: unhighlight on clicks outside links
While a heading is the #fragment, a click anywhere but on a link removes the fragment, like a click on the heading itself. Other links work as before, and a click that ends a text selection keeps the highlight.
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/simple/cgit-about-filter/cgit-about-filter.lua26
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>
]]