summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFatih Acet <acetfatih@gmail.com>2016-11-11 14:37:17 +0000
committerRémy Coutable <remy@rymai.me>2016-11-15 18:34:32 +0100
commitb4db38889e5210c908ca7e951a31a9945fc61bcd (patch)
treebd30cfd8b25ba1b2cecb48a8464fa3f25a986c66
parentc8b9f7a4a15f0381218a7512794efd6a86ddc57f (diff)
downloadgitlab-ce-b4db38889e5210c908ca7e951a31a9945fc61bcd.tar.gz
Merge branch '23520-mr-sticky-tabs-overlap-discussion-from-anchor' into 'master'
Account for fixed position MR when scrolling to elements This MR accounts for the new merge request fixed affix bar when scrolling to an element on the MR page. The fixed MR tabs bar was not being taken into account when shifting permalink scroll targets so that they are unobscured by navigation elements. Closes #23520 See merge request !7051 Signed-off-by: Rémy Coutable <remy@rymai.me>
-rw-r--r--app/assets/javascripts/application.js25
-rw-r--r--app/assets/javascripts/merge_request_tabs.js2
2 files changed, 19 insertions, 8 deletions
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index 8a61669822c..58f7adf2760 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -127,19 +127,30 @@
return $(document).off('scroll');
};
- window.shiftWindow = function() {
- return scrollBy(0, -100);
- };
-
document.addEventListener("page:fetch", unbindEvents);
- window.addEventListener("hashchange", 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() {
+ window.onload = function () {
// Scroll the window to avoid the topnav bar
// https://github.com/twitter/bootstrap/issues/1768
if (location.hash) {
- return setTimeout(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 3dde979185b..d282b2da2df 100644
--- a/app/assets/javascripts/merge_request_tabs.js
+++ b/app/assets/javascripts/merge_request_tabs.js
@@ -129,7 +129,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)", {