From dcfc2e10b82aa8620397f0eaeeeb88e76ceed119 Mon Sep 17 00:00:00 2001 From: Cynthia Lin Date: Fri, 15 Jun 2018 11:48:00 -0700 Subject: [PATCH] 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. --- static/js/portico/help.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/static/js/portico/help.js b/static/js/portico/help.js index 0a686bd0ea..a805ec5846 100644 --- a/static/js/portico/help.js +++ b/static/js/portico/help.js @@ -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 () {