Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEzekiel <theatlasroom@gmail.com>2019-01-22 07:47:16 +0300
committerEzekiel Kigbo <ekigbo@gitlab.com>2019-03-04 16:58:21 +0300
commitfde3f619ba557d5242b4fec07488b05398b4993d (patch)
treedad4e6c845597df5c031ae43092d7f73f25137e9 /app/assets/javascripts/contextual_sidebar.js
parentf8b1ef924e3b405cd72468fce236eb456a9a501d (diff)
Fixed navigation sidebar flashing open on page load
Adds the sidebar-collapsed-mobile class to the haml layouts and sets media queries to display the sidebar collapsed by default for sreen sizes greater than `sm` and less than `lg`
Diffstat (limited to 'app/assets/javascripts/contextual_sidebar.js')
-rw-r--r--app/assets/javascripts/contextual_sidebar.js29
1 files changed, 24 insertions, 5 deletions
diff --git a/app/assets/javascripts/contextual_sidebar.js b/app/assets/javascripts/contextual_sidebar.js
index 50efecb3475..eb30d14b6cd 100644
--- a/app/assets/javascripts/contextual_sidebar.js
+++ b/app/assets/javascripts/contextual_sidebar.js
@@ -29,7 +29,7 @@ export default class ContextualSidebar {
document.addEventListener('click', e => {
if (
!e.target.closest('.nav-sidebar') &&
- (bp.getBreakpointSize() === 'sm' || bp.getBreakpointSize() === 'md')
+ !ContextualSidebar.isDesktopBreakpoint(bp.getBreakpointSize())
) {
this.toggleCollapsedSidebar(true, true);
}
@@ -38,13 +38,23 @@ export default class ContextualSidebar {
this.$closeSidebar.on('click', () => this.toggleSidebarNav(false));
this.$overlay.on('click', () => this.toggleSidebarNav(false));
this.$sidebarToggle.on('click', () => {
- const value = !this.$sidebar.hasClass('sidebar-collapsed-desktop');
- this.toggleCollapsedSidebar(value, true);
+ const breakpoint = bp.getBreakpointSize();
+
+ if (!ContextualSidebar.isDesktopBreakpoint(breakpoint)) {
+ const collapsed = !this.$sidebar.hasClass('sidebar-collapsed-mobile');
+ this.toggleMobileCollapsedSidebar(collapsed);
+ } else if (breakpoint === 'lg') {
+ const value = !this.$sidebar.hasClass('sidebar-collapsed-desktop');
+ this.toggleCollapsedSidebar(value, true);
+ }
});
$(window).on('resize', () => _.debounce(this.render(), 100));
}
+ // TODO: use the breakpoints from breakpoints.js once they have been updated for bootstrap 4
+ // See related issue and discussion: https://gitlab.com/gitlab-org/gitlab-ce/issues/56745
+ static isDesktopBreakpoint = (_bp = '') => ['xl', 'lg'].indexOf(_bp) > -1;
static setCollapsedCookie(value) {
if (bp.getBreakpointSize() !== 'lg') {
return;
@@ -58,12 +68,21 @@ export default class ContextualSidebar {
this.$sidebar.removeClass('sidebar-collapsed-desktop');
}
+ toggleMobileCollapsedSidebar(collapsed) {
+ this.$sidebar.toggleClass('sidebar-collapsed-mobile', collapsed);
+ this.$sidebar.removeClass('sidebar-collapsed-desktop');
+ this.$page.toggleClass('page-with-icon-sidebar', true);
+ this.$page.toggleClass('page-with-contextual-sidebar', false);
+ requestIdleCallback(() => this.toggleSidebarOverflow());
+ }
+
toggleCollapsedSidebar(collapsed, saveCookie) {
const breakpoint = bp.getBreakpointSize();
if (this.$sidebar.length) {
this.$sidebar.toggleClass('sidebar-collapsed-desktop', collapsed);
this.$page.toggleClass('page-with-icon-sidebar', breakpoint === 'sm' ? true : collapsed);
+ this.$page.toggleClass('page-with-contextual-sidebar', true);
}
if (saveCookie) {
@@ -86,8 +105,8 @@ export default class ContextualSidebar {
const breakpoint = bp.getBreakpointSize();
- if (breakpoint === 'sm' || breakpoint === 'md') {
- this.toggleCollapsedSidebar(true, false);
+ if (!ContextualSidebar.isDesktopBreakpoint(breakpoint)) {
+ this.toggleMobileCollapsedSidebar(true);
} else if (breakpoint === 'lg') {
const collapse = parseBoolean(Cookies.get('sidebar_collapsed'));
this.toggleCollapsedSidebar(collapse, false);