summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/lib
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2017-09-28 16:13:21 +0100
committerPhil Hughes <me@iamphill.com>2017-09-29 09:24:56 +0100
commit333cb069afbef282618464206d8af50e8fd46cf7 (patch)
tree6ba1dca53cfc07562fc32f6f96f37bfa92210225 /app/assets/javascripts/lib
parent34da9a0f3784277555af91ed12ac6fe7d6e58fe6 (diff)
downloadgitlab-ce-333cb069afbef282618464206d8af50e8fd46cf7.tar.gz
Fixed anchored content not being scrolled into view
Correctly scrolls anchored content into view when the user loads the page. This is most obvious when the user loads a link note in a merge request & the page does not scroll down to the note. Closes #38326
Diffstat (limited to 'app/assets/javascripts/lib')
-rw-r--r--app/assets/javascripts/lib/utils/common_utils.js27
1 files changed, 11 insertions, 16 deletions
diff --git a/app/assets/javascripts/lib/utils/common_utils.js b/app/assets/javascripts/lib/utils/common_utils.js
index ea2d61af9be..423a25fbdfa 100644
--- a/app/assets/javascripts/lib/utils/common_utils.js
+++ b/app/assets/javascripts/lib/utils/common_utils.js
@@ -71,6 +71,7 @@ export const handleLocationHash = () => {
// This is required to handle non-unicode characters in hash
hash = decodeURIComponent(hash);
+ const target = document.getElementById(hash) || document.getElementById(`user-content-${hash}`);
const fixedTabs = document.querySelector('.js-tabs-affix');
const fixedDiffStats = document.querySelector('.js-diff-files-changed.is-stuck');
const fixedNav = document.querySelector('.navbar-gitlab');
@@ -78,25 +79,19 @@ export const handleLocationHash = () => {
let adjustment = 0;
if (fixedNav) adjustment -= fixedNav.offsetHeight;
- // scroll to user-generated markdown anchor if we cannot find a match
- if (document.getElementById(hash) === null) {
- const target = document.getElementById(`user-content-${hash}`);
- if (target && target.scrollIntoView) {
- target.scrollIntoView(true);
- window.scrollBy(0, adjustment);
- }
- } else {
- // only adjust for fixedTabs when not targeting user-generated content
- if (fixedTabs) {
- adjustment -= fixedTabs.offsetHeight;
- }
+ if (target && target.scrollIntoView) {
+ target.scrollIntoView(true);
+ }
- if (fixedDiffStats) {
- adjustment -= fixedDiffStats.offsetHeight;
- }
+ if (fixedTabs) {
+ adjustment -= fixedTabs.offsetHeight;
+ }
- window.scrollBy(0, adjustment);
+ if (fixedDiffStats) {
+ adjustment -= fixedDiffStats.offsetHeight;
}
+
+ window.scrollBy(0, adjustment);
};
// Check if element scrolled into viewport from above or below