2017-08-03 16:31:53 -04:00
|
|
|
import _ from 'underscore';
|
2017-08-10 05:42:36 -04:00
|
|
|
import Cookies from 'js-cookie';
|
2017-08-03 16:31:53 -04:00
|
|
|
|
2017-06-18 22:30:58 -04:00
|
|
|
export default {
|
|
|
|
init() {
|
|
|
|
if (!this.initialized) {
|
2017-08-10 05:42:36 -04:00
|
|
|
if (Cookies.get('new_nav') === 'true' && $('.js-issuable-sidebar').length) return;
|
|
|
|
|
2017-06-18 22:30:58 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|