summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2016-09-16 10:45:23 +0100
committerPhil Hughes <me@iamphill.com>2016-10-06 10:17:34 +0100
commitc65ea7a5c30ee44c859ac711f1054dab734bdb89 (patch)
tree10a987b981d63f4c22edc1f4df5b49373ed76642 /app
parent0ddeb6eb53d8fe6030e9945650f7594e2861dbf8 (diff)
downloadgitlab-ce-c65ea7a5c30ee44c859ac711f1054dab734bdb89.tar.gz
Merge request tabs stick when scrolling page
Closes #20548
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/merge_request_tabs.js38
-rw-r--r--app/assets/stylesheets/pages/merge_requests.scss9
-rw-r--r--app/views/projects/merge_requests/_show.html.haml2
3 files changed, 48 insertions, 1 deletions
diff --git a/app/assets/javascripts/merge_request_tabs.js b/app/assets/javascripts/merge_request_tabs.js
index bec11a198a1..f685af7d97e 100644
--- a/app/assets/javascripts/merge_request_tabs.js
+++ b/app/assets/javascripts/merge_request_tabs.js
@@ -68,6 +68,7 @@
this._location = location;
this.bindEvents();
this.activateTab(this.opts.action);
+ this.initAffix();
}
MergeRequestTabs.prototype.bindEvents = function() {
@@ -367,6 +368,43 @@
// Only when sidebar is collapsed
};
+ MergeRequestTabs.prototype.initAffix = function () {
+ // Screen space on small screens is usually very sparse
+ // So we dont affix the tabs on these
+ if (Breakpoints.get().getBreakpointSize() === 'xs') return;
+
+ var $tabs = $('.js-tabs-affix'),
+ tabsWidth = $tabs.outerWidth(),
+ $diffTabs = $('#diff-notes-app'),
+ offsetTop = $tabs.offset().top - ($('.navbar-fixed-top').height() + $('.layout-nav').height());
+
+ $tabs.off('affix.bs.affix affix-top.bs.affix')
+ .affix({
+ offset: offsetTop
+ }).on('affix.bs.affix', function () {
+ $tabs.css({
+ left: $tabs.offset().left,
+ width: tabsWidth
+ });
+ $diffTabs.css({
+ marginTop: $tabs.height()
+ });
+ }).on('affix-top.bs.affix', function () {
+ $tabs.css({
+ left: '',
+ width: ''
+ });
+ $diffTabs.css({
+ marginTop: ''
+ });
+ });
+
+ // Fix bug when reloading the page already scrolling
+ if ($tabs.hasClass('affix')) {
+ $tabs.trigger('affix.bs.affix');
+ }
+ };
+
return MergeRequestTabs;
})();
diff --git a/app/assets/stylesheets/pages/merge_requests.scss b/app/assets/stylesheets/pages/merge_requests.scss
index bc8693ae467..d01aaa4be51 100644
--- a/app/assets/stylesheets/pages/merge_requests.scss
+++ b/app/assets/stylesheets/pages/merge_requests.scss
@@ -421,3 +421,12 @@
margin-bottom: 20px;
}
}
+
+.merge-request-tabs {
+ background-color: #fff;
+
+ &.affix {
+ top: 100px;
+ z-index: 9;
+ }
+}
diff --git a/app/views/projects/merge_requests/_show.html.haml b/app/views/projects/merge_requests/_show.html.haml
index 9f34ca9ff4e..351c9d6ff91 100644
--- a/app/views/projects/merge_requests/_show.html.haml
+++ b/app/views/projects/merge_requests/_show.html.haml
@@ -47,7 +47,7 @@
= link_to "command line", "#modal_merge_info", class: "how_to_merge_link vlink", title: "How To Merge", "data-toggle" => "modal"
- if @commits_count.nonzero?
- %ul.merge-request-tabs.nav-links.no-top.no-bottom
+ %ul.merge-request-tabs.nav-links.no-top.no-bottom.js-tabs-affix
%li.notes-tab
= link_to namespace_project_merge_request_path(@project.namespace, @project, @merge_request), data: { target: 'div#notes', action: 'notes', toggle: 'tab' } do
Discussion