diff options
author | Kohei Yoshino <kohei.yoshino@gmail.com> | 2017-12-18 21:06:11 +0100 |
---|---|---|
committer | Dylan William Hardison <dylan@hardison.net> | 2017-12-18 21:06:11 +0100 |
commit | bc8533f5e9e211f250b5bc3247797feac0f1303b (patch) | |
tree | a235a167a4e724490f2e16a28bc732b01c507e66 /js/global.js | |
parent | 334bead74bc9c5e819f14946726eaad40986d636 (diff) | |
download | bugzilla-bc8533f5e9e211f250b5bc3247797feac0f1303b.tar.gz bugzilla-bc8533f5e9e211f250b5bc3247797feac0f1303b.tar.xz |
Bug 905763 - Fix named anchors in various pages so that the Sandstone theme header can be set to a fixed position
Diffstat (limited to 'js/global.js')
-rw-r--r-- | js/global.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/js/global.js b/js/global.js index b7b517631..3a4074d27 100644 --- a/js/global.js +++ b/js/global.js @@ -190,3 +190,24 @@ $().ready(function() { $('.bz_autocomplete').attr('autocomplete', 'off'); }); }); + +/** + * If the URL contains a hash like #c10, scroll down the page to show the + * element below the fixed global header. This workaround is required for + * comments on show_bug.cgi, components on describecomponents.cgi, etc. + */ +const scroll_element_into_view = () => { + if (location.hash) { + const $header = document.querySelector('#header'); + const $comment = document.querySelector(location.hash); + + if ($comment) { + window.setTimeout(() => { + window.scrollTo(0, $comment.offsetTop - $header.offsetHeight - 20); + }, 100); + } + } +} + +window.addEventListener('load', scroll_element_into_view, { once: true }); +window.addEventListener('hashchange', scroll_element_into_view); |