help: Fix broken anchor link scrolling in documentation pages.

Whenever a link is clicked, the page link changes, and the content
of the `.markdown .content` node updates, preventing the old
listener to catch any future anchor link clicks. 

We attach the listener to the document instead and only activate
it when the target element is a proper anchor link heading.

Fixes #9767.
This commit is contained in:
Cynthia Lin 2018-06-15 11:48:00 -07:00 committed by Tim Abbott
parent 3dd9f61851
commit dcfc2e10b8

View File

@ -178,8 +178,8 @@ function scrollToHash(container) {
$('.help .sidebar h1, .help .sidebar h2, .help .sidebar h3').removeAttr('id');
// Scroll to anchor link when clicked
$('.markdown .content h1, .markdown .content h2, .markdown .content h3').on('click', function () {
window.location.href = window.location.href.replace(/#.*/, '') + '#' + $(this).attr("id");
$(document).on('click', '.markdown .content h1, .markdown .content h2, .markdown .content h3', function () {
location.hash = $(this).attr("id");
});
$(".hamburger").click(function () {