diff options
-rw-r--r-- | js/comments.js | 20 | ||||
-rw-r--r-- | js/global.js | 21 | ||||
-rw-r--r-- | skins/standard/global.css | 1 |
3 files changed, 22 insertions, 20 deletions
diff --git a/js/comments.js b/js/comments.js index 88ba49364..82c93e561 100644 --- a/js/comments.js +++ b/js/comments.js @@ -178,23 +178,3 @@ function getText(element) { } return text; } - -/** - * If the URL contains a comment ID like #c10, scroll down the page to show the - * entire comment below the fixed global header. - */ -function scroll_comment_into_view() { - if (location.hash.match(/^#c\d+$/)) { - var $header = document.querySelector('#header'); - var $comment = document.querySelector(location.hash); - - if ($comment) { - window.setTimeout(function() { - window.scrollTo(0, $comment.offsetTop - $header.offsetHeight - 20); - }, 100); - } - } -} - -window.addEventListener('load', scroll_comment_into_view, { once: true }); -window.addEventListener('hashchange', scroll_comment_into_view); 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); diff --git a/skins/standard/global.css b/skins/standard/global.css index 3b58c1d63..12dab11f5 100644 --- a/skins/standard/global.css +++ b/skins/standard/global.css @@ -39,6 +39,7 @@ font-family: sans-serif; color: #000; background: #fff url("global/body-back.gif") repeat-x; + scroll-behavior: smooth; } body, td, th, input { font-family: Verdana, sans-serif; |