69f9ee28f8
This isn't required with the new navigation as it is always position fixed so we are just creating a scroll event listener that will never actually do anything
37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
import _ from 'underscore';
|
|
import Cookies from 'js-cookie';
|
|
|
|
export default {
|
|
init() {
|
|
if (!this.initialized) {
|
|
if (Cookies.get('new_nav') === 'true' && $('.js-issuable-sidebar').length) return;
|
|
|
|
this.$window = $(window);
|
|
this.$rightSidebar = $('.js-right-sidebar');
|
|
this.$navHeight = $('.navbar-gitlab').outerHeight() +
|
|
$('.layout-nav').outerHeight() +
|
|
$('.sub-nav-scroll').outerHeight();
|
|
|
|
const throttledSetSidebarHeight = _.throttle(() => this.setSidebarHeight(), 20);
|
|
const debouncedSetSidebarHeight = _.debounce(() => this.setSidebarHeight(), 200);
|
|
|
|
this.$window.on('scroll', throttledSetSidebarHeight);
|
|
this.$window.on('resize', debouncedSetSidebarHeight);
|
|
this.initialized = true;
|
|
}
|
|
},
|
|
|
|
setSidebarHeight() {
|
|
const currentScrollDepth = window.pageYOffset || 0;
|
|
const diff = this.$navHeight - currentScrollDepth;
|
|
|
|
if (diff > 0) {
|
|
const newSidebarHeight = window.innerHeight - diff;
|
|
this.$rightSidebar.outerHeight(newSidebarHeight);
|
|
this.sidebarHeightIsCustom = true;
|
|
} else if (this.sidebarHeightIsCustom) {
|
|
this.$rightSidebar.outerHeight('100%');
|
|
this.sidebarHeightIsCustom = false;
|
|
}
|
|
},
|
|
};
|