From d48664fc5f77bcda43df65a3367d1fb2d2680b22 Mon Sep 17 00:00:00 2001 From: Aman Jain Date: Tue, 13 Feb 2018 00:44:24 +0530 Subject: [PATCH] help: Fix links with query selector from left sidebar. This resolves the issue of scrolling to correct position when loaded from left sidebar to a link with query selector. Fixes #6714. --- static/js/portico/help.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/static/js/portico/help.js b/static/js/portico/help.js index c5e4d16182..91793c1b3d 100644 --- a/static/js/portico/help.js +++ b/static/js/portico/help.js @@ -69,6 +69,15 @@ function render_code_sections() { } } +function scrollToHash(container) { + var hash = window.location.hash; + if (hash !== '') { + container.scrollTop = $(hash).position().top - $('.markdown .content').position().top; + } else { + container.scrollTop = 0; + } +} + (function () { var html_map = {}; var loading = { @@ -117,6 +126,7 @@ function render_code_sections() { $(".markdown .content").html(html_map[path]); Ps.update(container); render_code_sections(); + scrollToHash(container); } else { loading.name = path; @@ -125,10 +135,10 @@ function render_code_sections() { $(".markdown .content").html(html_map[path]); loading.name = null; Ps.update(container); + scrollToHash(container); }); } - container.scrollTop = 0; $(".sidebar").removeClass("show"); e.preventDefault();