2020-06-19 00:09:12 +00:00
|
|
|
import { GlBreakpointInstance as bp } from '@gitlab/ui/dist/utils';
|
2021-02-14 18:09:20 +00:00
|
|
|
import $ from 'jquery';
|
2020-06-19 00:09:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This behavior collapses the right sidebar
|
|
|
|
* if the window size changes
|
|
|
|
*
|
|
|
|
* @sentrify
|
|
|
|
*/
|
|
|
|
export default () => {
|
|
|
|
let bootstrapBreakpoint = bp.getBreakpointSize();
|
|
|
|
|
|
|
|
$(window).on('resize.app', () => {
|
|
|
|
const oldBootstrapBreakpoint = bootstrapBreakpoint;
|
|
|
|
bootstrapBreakpoint = bp.getBreakpointSize();
|
|
|
|
|
|
|
|
if (bootstrapBreakpoint !== oldBootstrapBreakpoint) {
|
|
|
|
const breakpointSizes = ['md', 'sm', 'xs'];
|
|
|
|
|
|
|
|
if (breakpointSizes.includes(bootstrapBreakpoint)) {
|
2020-10-03 03:08:48 +00:00
|
|
|
const $toggleContainer = $('.js-sidebar-toggle-container');
|
|
|
|
const isExpanded = $toggleContainer.data('is-expanded');
|
|
|
|
const $expandIcon = $('.js-sidebar-expand');
|
|
|
|
|
|
|
|
if (isExpanded) {
|
|
|
|
const $sidebarGutterToggle = $expandIcon.closest('.js-sidebar-toggle');
|
|
|
|
|
2020-06-19 00:09:12 +00:00
|
|
|
$sidebarGutterToggle.trigger('click');
|
|
|
|
}
|
|
|
|
|
|
|
|
const sidebarGutterVueToggleEl = document.querySelector('.js-sidebar-vue-toggle');
|
|
|
|
|
|
|
|
// Sidebar has an icon which corresponds to collapsing the sidebar
|
|
|
|
// only then trigger the click.
|
2020-10-16 15:08:46 +00:00
|
|
|
if (
|
|
|
|
sidebarGutterVueToggleEl &&
|
|
|
|
!sidebarGutterVueToggleEl.classList.contains('js-sidebar-collapsed')
|
|
|
|
) {
|
|
|
|
if (sidebarGutterVueToggleEl) {
|
|
|
|
sidebarGutterVueToggleEl.click();
|
2020-06-19 00:09:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|