help_pages: Preserve anchor highlights.

This commit assigns a `.scroll-target` class to preserve any URL
fragment whose corresponding ID is on the self-same page as the
activating link.

This accommodates a side-effect of the fetch-based page-loading
logic, which seems to lose the `:target` reference once a load
or reload is complete.
This commit is contained in:
Karl Stolley 2023-05-15 11:18:11 -05:00 committed by Tim Abbott
parent ceec61ba10
commit b852da6eed
2 changed files with 6 additions and 1 deletions

View File

@ -70,6 +70,10 @@ function scrollToHash(simplebar) {
const scrollbar = simplebar.getScrollElement();
if (hash !== "" && $(hash).length > 0) {
const position = $(hash).position().top - $(scrollbar.firstChild).position().top;
// Preserve a reference to the scroll target, so it is not lost (and the highlight
// along with it) when the page is updated via fetch
const $scroll_target = $(hash);
$scroll_target.addClass("scroll-target");
scrollbar.scrollTop = position;
} else {
scrollbar.scrollTop = 0;

View File

@ -249,7 +249,8 @@ html {
width: calc(100vw - 300px);
height: calc(100vh - 59px);
& :target {
& :target,
& .scroll-target {
/* Match to where simplebar scrolls */
scroll-margin-top: 20px;
/* Increase the highlighted space around the text... */