summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFatih Acet <acetfatih@gmail.com>2016-11-11 14:37:17 +0000
committerFatih Acet <acetfatih@gmail.com>2016-11-11 14:37:17 +0000
commit41899c2a00ba67b1aa8f72006b48b2652e206e99 (patch)
treed257b419f939f71e6fec7a0bfaa5cbe390d42deb
parent7957b204052a5701e9dea660ef170d6935c889a6 (diff)
parentf02f08f53c551c79cb26457182b584e4f38f4437 (diff)
downloadgitlab-ce-41899c2a00ba67b1aa8f72006b48b2652e206e99.tar.gz
Merge branch '23520-mr-sticky-tabs-overlap-discussion-from-anchor' into 'master'
Account for fixed position MR when scrolling to elements ## What does this MR do? This MR accounts for the new merge request fixed affix bar when scrolling to an element on the MR page. ## Are there points in the code the reviewer needs to double check? ## Why was this MR needed? The fixed MR tabs bar was not being taken into account when shifting permalink scroll targets so that they are unobscured by navigation elements. ## Screenshots (if relevant) Issues discussion permalink: ![Screen_Shot_2016-10-26_at_12.29.26_AM](/uploads/e278f784252f2b79c466f56b4f36d198/Screen_Shot_2016-10-26_at_12.29.26_AM.png) Merge request discussion permalink: ![Screen_Shot_2016-10-26_at_12.28.26_AM](/uploads/1e57357fffb815b217484f09377f3c23/Screen_Shot_2016-10-26_at_12.28.26_AM.png) Merge request diff permalink: ![Screen_Shot_2016-10-26_at_12.29.02_AM](/uploads/269f3a4a4075932355f665322387db86/Screen_Shot_2016-10-26_at_12.29.02_AM.png) Commit diff page permalinks work as well, but aren't highlighted currently (see: #23696) ## Does this MR meet the acceptance criteria? - [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG.md) entry added - Tests - [x] All builds are passing - [x] Conform by the [merge request performance guides](http://docs.gitlab.com/ce/development/merge_request_performance_guidelines.html) - [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides) - [x] Branch has no merge conflicts with `master` (if it does - rebase it please) - [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits) ## What are the relevant issue numbers? Closes #23520 See merge request !7051
-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)", {