summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Bennett <lukeeeebennettplus@gmail.com>2016-10-21 23:52:17 +0100
committerLuke "Jared" Bennett <lbennett@gitlab.com>2016-11-10 01:16:21 +0000
commitf02f08f53c551c79cb26457182b584e4f38f4437 (patch)
tree0784e3f79fa7ddfed07bee11ed08225c9f38d9a4
parent0c99e5d0b6b457ef7db2c36f1394fad5c63d1142 (diff)
downloadgitlab-ce-23520-mr-sticky-tabs-overlap-discussion-from-anchor.tar.gz
Account for merge request fixed affix bar23520-mr-sticky-tabs-overlap-discussion-from-anchor
account for merge request fixed affix bar when adjusting scroll targets
-rw-r--r--app/assets/javascripts/application.js19
-rw-r--r--app/assets/javascripts/merge_request_tabs.js2
2 files changed, 19 insertions, 2 deletions
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index 33c1708e1a9..5c047dd4481 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -58,11 +58,28 @@
document.addEventListener('page:fetch', gl.utils.cleanupBeforeFetch);
window.addEventListener('hashchange', gl.utils.shiftWindow);
+ // automatically adjust scroll position for hash urls taking the height of the navbar into account
+ // https://github.com/twitter/bootstrap/issues/1768
+ window.adjustScroll = function() {
+ var navbar = document.querySelector('.navbar-gitlab');
+ var subnav = document.querySelector('.layout-nav');
+ var fixedTabs = document.querySelector('.js-tabs-affix');
+
+ adjustment = 0;
+ if (navbar) adjustment -= navbar.offsetHeight;
+ if (subnav) adjustment -= subnav.offsetHeight;
+ if (fixedTabs) adjustment -= fixedTabs.offsetHeight;
+
+ return scrollBy(0, adjustment);
+ };
+
+ window.addEventListener("hashchange", adjustScroll);
+
window.onload = function () {
// Scroll the window to avoid the topnav bar
// https://github.com/twitter/bootstrap/issues/1768
if (location.hash) {
- return setTimeout(gl.utils.shiftWindow, 100);
+ return setTimeout(adjustScroll, 100);
}
};
diff --git a/app/assets/javascripts/merge_request_tabs.js b/app/assets/javascripts/merge_request_tabs.js
index 860ee5df57e..f06b10a9cf7 100644
--- a/app/assets/javascripts/merge_request_tabs.js
+++ b/app/assets/javascripts/merge_request_tabs.js
@@ -130,7 +130,7 @@
MergeRequestTabs.prototype.scrollToElement = function(container) {
var $el, navBarHeight;
if (window.location.hash) {
- navBarHeight = $('.navbar-gitlab').outerHeight() + $('.layout-nav').outerHeight();
+ navBarHeight = $('.navbar-gitlab').outerHeight() + $('.layout-nav').outerHeight() + document.querySelector('.js-tabs-affix').offsetHeight;
$el = $(container + " " + window.location.hash + ":not(.match)");
if ($el.length) {
return $.scrollTo(container + " " + window.location.hash + ":not(.match)", {