Make hijacked docs links update the location hash (#4535)

If you click on a section title, we hijack the link to animate
it. However, we did not update the location hash. This makes it quite
annoying to copy links to a specific section.

This PR sets the jquery animate callback to update the hash as
well. I’ve also included a small fix for the link on the section title
which previously produced an error in the JS console since "#" is not
a valid jquery selector.

changelog_begin
changelog_end
This commit is contained in:
Moritz Kiefer 2020-02-17 10:32:25 +01:00 committed by GitHub
parent c64919cd58
commit 29ac82ae1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -486,8 +486,16 @@ $(document).ready(function () {
if ($(window).width() < 1600) {
$('.content-menu').toggleClass('collapsed');
}
var position = $($(this).attr('href')).offset().top;
$("html, body").animate({scrollTop: position}, "slow");
var href = $(this).attr('href');
// Special treatment for going back to the top since those links
// don't have an id and just go to #
var position = href === "#" ? 0 : $(href).offset().top;
$("html, body").animate(
{scrollTop: position},
"slow",
function () {
window.location.hash = href;
});
ev.preventDefault();
});
// sections padding
@ -699,4 +707,4 @@ if (searchEngine === 'sphinx') {
}, 50);
})
});
}
}