summaryrefslogtreecommitdiffstats
path: root/js/comments.js
diff options
context:
space:
mode:
authorKohei Yoshino <kohei.yoshino@gmail.com>2017-12-13 22:06:06 +0100
committerDylan William Hardison <dylan@hardison.net>2017-12-13 22:06:06 +0100
commit2e5d910d9401c4fa8f105d8f9502d9e4ea27bb99 (patch)
treeaba81e2eedc8af3136af73af3beba04c092ff80c /js/comments.js
parent48fe3a1e0a4a833aa14e7f95136d0e4542959eb8 (diff)
downloadbugzilla-2e5d910d9401c4fa8f105d8f9502d9e4ea27bb99.tar.gz
bugzilla-2e5d910d9401c4fa8f105d8f9502d9e4ea27bb99.tar.xz
Bug 1376826 - New HTML Header for BMO
Diffstat (limited to 'js/comments.js')
-rw-r--r--js/comments.js22
1 files changed, 21 insertions, 1 deletions
diff --git a/js/comments.js b/js/comments.js
index 12bc00d46..88ba49364 100644
--- a/js/comments.js
+++ b/js/comments.js
@@ -144,7 +144,7 @@ function goto_add_comments( anchor ){
anchor = (anchor || "add_comment");
// we need this line to expand the comment box
document.getElementById('comment').focus();
- setTimeout(function(){
+ setTimeout(function(){
document.location.hash = anchor;
// firefox doesn't seem to keep focus through the anchor change
document.getElementById('comment').focus();
@@ -178,3 +178,23 @@ 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);