summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/right_sidebar.js
diff options
context:
space:
mode:
authorTim Zallmann <tzallmann@gitlab.com>2017-06-20 16:45:26 +0200
committerTim Zallmann <tzallmann@gitlab.com>2017-06-20 16:45:26 +0200
commit278bf413bf4e395e268aa6bacade828e9f58d064 (patch)
tree4224004367013ba02b5bba24bdfcda3bb03ae4e8 /app/assets/javascripts/right_sidebar.js
parentbf57a7e80c44080dc7ec0fd774148afdae29cc31 (diff)
downloadgitlab-ce-278bf413bf4e395e268aa6bacade828e9f58d064.tar.gz
Fixes scrolling + improves Performance through assigning found $ elements to variables
Diffstat (limited to 'app/assets/javascripts/right_sidebar.js')
-rw-r--r--app/assets/javascripts/right_sidebar.js21
1 files changed, 15 insertions, 6 deletions
diff --git a/app/assets/javascripts/right_sidebar.js b/app/assets/javascripts/right_sidebar.js
index b71c3097706..da7c0c5a36c 100644
--- a/app/assets/javascripts/right_sidebar.js
+++ b/app/assets/javascripts/right_sidebar.js
@@ -7,6 +7,13 @@ import Cookies from 'js-cookie';
function Sidebar(currentUser) {
this.toggleTodo = this.toggleTodo.bind(this);
this.sidebar = $('aside');
+
+ this.$sidebarInner = this.sidebar.find('.issuable-sidebar');
+ this.$navGitlab = $('.navbar-gitlab');
+ this.$layoutNav = $('.layout-nav');
+ this.$subScroll = $('.sub-nav-scroll');
+ this.$rightSidebar = $('.js-right-sidebar');
+
this.removeListeners();
this.addEventListeners();
}
@@ -21,14 +28,15 @@ import Cookies from 'js-cookie';
Sidebar.prototype.addEventListeners = function() {
const $document = $(document);
- const throttledSetSidebarHeight = _.throttle(this.setSidebarHeight, 10);
+ const throttledSetSidebarHeight = _.throttle(this.setSidebarHeight.bind(this), 20);
+ const debouncedSetSidebarHeight = _.debounce(this.setSidebarHeight.bind(this), 200);
this.sidebar.on('click', '.sidebar-collapsed-icon', this, this.sidebarCollapseClicked);
$('.dropdown').on('hidden.gl.dropdown', this, this.onSidebarDropdownHidden);
$('.dropdown').on('loading.gl.dropdown', this.sidebarDropdownLoading);
$('.dropdown').on('loaded.gl.dropdown', this.sidebarDropdownLoaded);
$(window).on('resize', () => throttledSetSidebarHeight());
- $document.on('scroll', () => throttledSetSidebarHeight());
+ $document.on('scroll', () => debouncedSetSidebarHeight());
$document.on('click', '.js-sidebar-toggle', function(e, triggered) {
var $allGutterToggleIcons, $this, $thisIcon;
e.preventDefault();
@@ -207,13 +215,14 @@ import Cookies from 'js-cookie';
};
Sidebar.prototype.setSidebarHeight = function() {
- const $navHeight = $('.navbar-gitlab').outerHeight() + $('.layout-nav').outerHeight() + $('.sub-nav-scroll').outerHeight();
- const $rightSidebar = $('.js-right-sidebar');
+ const $navHeight = this.$navGitlab.outerHeight() + this.$layoutNav.outerHeight() + (this.$subScroll ? this.$subScroll.outerHeight() : 0);
const diff = $navHeight - $(window).scrollTop();
if (diff > 0) {
- $rightSidebar.outerHeight($(window).height() - diff);
+ this.$rightSidebar.outerHeight($(window).height() - diff);
+ this.$sidebarInner.height('100%');
} else {
- $rightSidebar.outerHeight('100%');
+ this.$rightSidebar.outerHeight('100%');
+ this.$sidebarInner.height('');
}
};