summaryrefslogtreecommitdiff
path: root/app/assets/javascripts
diff options
context:
space:
mode:
authorFilipa Lacerda <filipa@gitlab.com>2017-09-29 15:14:22 +0000
committerFilipa Lacerda <filipa@gitlab.com>2017-09-29 15:14:22 +0000
commit49fdaf9ee8e939be389da65a0a691ce0c8b498c2 (patch)
treeceed9350f628ca545ec6d2f8a74edcf11045bedc /app/assets/javascripts
parent39b4dab090811e5905c6ff3e62edc876b482d52f (diff)
parentd729aa73836c4b74b09a8b84ad97694ee858f34c (diff)
downloadgitlab-ce-49fdaf9ee8e939be389da65a0a691ce0c8b498c2.tar.gz
Merge branch 'hash-mr-scroll-load' into 'master'
Fixed anchored content not being scrolled into view Closes #38326 See merge request gitlab-org/gitlab-ce!14562
Diffstat (limited to 'app/assets/javascripts')
-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