From 187a01a8ee87f0978da81720bad28938df0e91c8 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sun, 31 May 2020 16:45:54 +0300 Subject: [PATCH] Return early. --- build/js/ControlSidebar.js | 128 +++++++++++++++++++------------------ build/js/Layout.js | 30 +++++---- build/js/PushMenu.js | 54 ++++++++-------- 3 files changed, 111 insertions(+), 101 deletions(-) diff --git a/build/js/ControlSidebar.js b/build/js/ControlSidebar.js index 39a17dbf0..9abbe32f8 100644 --- a/build/js/ControlSidebar.js +++ b/build/js/ControlSidebar.js @@ -134,6 +134,10 @@ const ControlSidebar = ($ => { } _fixScrollHeight() { + if (!$('body').hasClass(ClassName.LAYOUT_FIXED)) { + return + } + const heights = { scroll: $(document).height(), window: $(window).height(), @@ -148,92 +152,92 @@ const ControlSidebar = ($ => { let navbarFixed = false let footerFixed = false - if ($('body').hasClass(ClassName.LAYOUT_FIXED)) { - if ( - $('body').hasClass(ClassName.NAVBAR_FIXED) || - $('body').hasClass(ClassName.NAVBAR_SM_FIXED) || - $('body').hasClass(ClassName.NAVBAR_MD_FIXED) || - $('body').hasClass(ClassName.NAVBAR_LG_FIXED) || - $('body').hasClass(ClassName.NAVBAR_XL_FIXED) - ) { - if ($(Selector.HEADER).css('position') === 'fixed') { - navbarFixed = true - } + if ( + $('body').hasClass(ClassName.NAVBAR_FIXED) || + $('body').hasClass(ClassName.NAVBAR_SM_FIXED) || + $('body').hasClass(ClassName.NAVBAR_MD_FIXED) || + $('body').hasClass(ClassName.NAVBAR_LG_FIXED) || + $('body').hasClass(ClassName.NAVBAR_XL_FIXED) + ) { + if ($(Selector.HEADER).css('position') === 'fixed') { + navbarFixed = true } + } - if ( - $('body').hasClass(ClassName.FOOTER_FIXED) || - $('body').hasClass(ClassName.FOOTER_SM_FIXED) || - $('body').hasClass(ClassName.FOOTER_MD_FIXED) || - $('body').hasClass(ClassName.FOOTER_LG_FIXED) || - $('body').hasClass(ClassName.FOOTER_XL_FIXED) - ) { - if ($(Selector.FOOTER).css('position') === 'fixed') { - footerFixed = true - } + if ( + $('body').hasClass(ClassName.FOOTER_FIXED) || + $('body').hasClass(ClassName.FOOTER_SM_FIXED) || + $('body').hasClass(ClassName.FOOTER_MD_FIXED) || + $('body').hasClass(ClassName.FOOTER_LG_FIXED) || + $('body').hasClass(ClassName.FOOTER_XL_FIXED) + ) { + if ($(Selector.FOOTER).css('position') === 'fixed') { + footerFixed = true } + } - if (positions.top === 0 && positions.bottom === 0) { + if (positions.top === 0 && positions.bottom === 0) { + $(Selector.CONTROL_SIDEBAR).css('bottom', heights.footer) + $(Selector.CONTROL_SIDEBAR).css('top', heights.header) + $(Selector.CONTROL_SIDEBAR + ', ' + Selector.CONTROL_SIDEBAR + ' ' + Selector.CONTROL_SIDEBAR_CONTENT).css('height', heights.window - (heights.header + heights.footer)) + } else if (positions.bottom <= heights.footer) { + if (footerFixed === false) { + $(Selector.CONTROL_SIDEBAR).css('bottom', heights.footer - positions.bottom) + $(Selector.CONTROL_SIDEBAR + ', ' + Selector.CONTROL_SIDEBAR + ' ' + Selector.CONTROL_SIDEBAR_CONTENT).css('height', heights.window - (heights.footer - positions.bottom)) + } else { $(Selector.CONTROL_SIDEBAR).css('bottom', heights.footer) - $(Selector.CONTROL_SIDEBAR).css('top', heights.header) - $(Selector.CONTROL_SIDEBAR + ', ' + Selector.CONTROL_SIDEBAR + ' ' + Selector.CONTROL_SIDEBAR_CONTENT).css('height', heights.window - (heights.header + heights.footer)) - } else if (positions.bottom <= heights.footer) { - if (footerFixed === false) { - $(Selector.CONTROL_SIDEBAR).css('bottom', heights.footer - positions.bottom) - $(Selector.CONTROL_SIDEBAR + ', ' + Selector.CONTROL_SIDEBAR + ' ' + Selector.CONTROL_SIDEBAR_CONTENT).css('height', heights.window - (heights.footer - positions.bottom)) - } else { - $(Selector.CONTROL_SIDEBAR).css('bottom', heights.footer) - } - } else if (positions.top <= heights.header) { - if (navbarFixed === false) { - $(Selector.CONTROL_SIDEBAR).css('top', heights.header - positions.top) - $(Selector.CONTROL_SIDEBAR + ', ' + Selector.CONTROL_SIDEBAR + ' ' + Selector.CONTROL_SIDEBAR_CONTENT).css('height', heights.window - (heights.header - positions.top)) - } else { - $(Selector.CONTROL_SIDEBAR).css('top', heights.header) - } - } else if (navbarFixed === false) { - $(Selector.CONTROL_SIDEBAR).css('top', 0) - $(Selector.CONTROL_SIDEBAR + ', ' + Selector.CONTROL_SIDEBAR + ' ' + Selector.CONTROL_SIDEBAR_CONTENT).css('height', heights.window) + } + } else if (positions.top <= heights.header) { + if (navbarFixed === false) { + $(Selector.CONTROL_SIDEBAR).css('top', heights.header - positions.top) + $(Selector.CONTROL_SIDEBAR + ', ' + Selector.CONTROL_SIDEBAR + ' ' + Selector.CONTROL_SIDEBAR_CONTENT).css('height', heights.window - (heights.header - positions.top)) } else { $(Selector.CONTROL_SIDEBAR).css('top', heights.header) } + } else if (navbarFixed === false) { + $(Selector.CONTROL_SIDEBAR).css('top', 0) + $(Selector.CONTROL_SIDEBAR + ', ' + Selector.CONTROL_SIDEBAR + ' ' + Selector.CONTROL_SIDEBAR_CONTENT).css('height', heights.window) + } else { + $(Selector.CONTROL_SIDEBAR).css('top', heights.header) } } _fixHeight() { + if (!$('body').hasClass(ClassName.LAYOUT_FIXED)) { + return + } + const heights = { window: $(window).height(), header: $(Selector.HEADER).outerHeight(), footer: $(Selector.FOOTER).outerHeight() } - if ($('body').hasClass(ClassName.LAYOUT_FIXED)) { - let sidebarHeight = heights.window - heights.header + let sidebarHeight = heights.window - heights.header - if ( - $('body').hasClass(ClassName.FOOTER_FIXED) || + if ( + $('body').hasClass(ClassName.FOOTER_FIXED) || $('body').hasClass(ClassName.FOOTER_SM_FIXED) || $('body').hasClass(ClassName.FOOTER_MD_FIXED) || $('body').hasClass(ClassName.FOOTER_LG_FIXED) || $('body').hasClass(ClassName.FOOTER_XL_FIXED) - ) { - if ($(Selector.FOOTER).css('position') === 'fixed') { - sidebarHeight = heights.window - heights.header - heights.footer + ) { + if ($(Selector.FOOTER).css('position') === 'fixed') { + sidebarHeight = heights.window - heights.header - heights.footer + } + } + + $(Selector.CONTROL_SIDEBAR + ' ' + Selector.CONTROL_SIDEBAR_CONTENT).css('height', sidebarHeight) + + if (typeof $.fn.overlayScrollbars !== 'undefined') { + $(Selector.CONTROL_SIDEBAR + ' ' + Selector.CONTROL_SIDEBAR_CONTENT).overlayScrollbars({ + className: this._config.scrollbarTheme, + sizeAutoCapable: true, + scrollbars: { + autoHide: this._config.scrollbarAutoHide, + clickScrolling: true } - } - - $(Selector.CONTROL_SIDEBAR + ' ' + Selector.CONTROL_SIDEBAR_CONTENT).css('height', sidebarHeight) - - if (typeof $.fn.overlayScrollbars !== 'undefined') { - $(Selector.CONTROL_SIDEBAR + ' ' + Selector.CONTROL_SIDEBAR_CONTENT).overlayScrollbars({ - className: this._config.scrollbarTheme, - sizeAutoCapable: true, - scrollbars: { - autoHide: this._config.scrollbarAutoHide, - clickScrolling: true - } - }) - } + }) } } diff --git a/build/js/Layout.js b/build/js/Layout.js index 109f7cc5d..bed440628 100644 --- a/build/js/Layout.js +++ b/build/js/Layout.js @@ -93,21 +93,23 @@ const Layout = ($ => { } } - if ($('body').hasClass(ClassName.LAYOUT_FIXED)) { - if (offset !== false) { - $(Selector.CONTENT).css('min-height', (max + offset) - heights.header - heights.footer) - } + if (!$('body').hasClass(ClassName.LAYOUT_FIXED)) { + return + } - if (typeof $.fn.overlayScrollbars !== 'undefined') { - $(Selector.SIDEBAR).overlayScrollbars({ - className: this._config.scrollbarTheme, - sizeAutoCapable: true, - scrollbars: { - autoHide: this._config.scrollbarAutoHide, - clickScrolling: true - } - }) - } + if (offset !== false) { + $(Selector.CONTENT).css('min-height', (max + offset) - heights.header - heights.footer) + } + + if (typeof $.fn.overlayScrollbars !== 'undefined') { + $(Selector.SIDEBAR).overlayScrollbars({ + className: this._config.scrollbarTheme, + sizeAutoCapable: true, + scrollbars: { + autoHide: this._config.scrollbarAutoHide, + clickScrolling: true + } + }) } } diff --git a/build/js/PushMenu.js b/build/js/PushMenu.js index 886e7a70f..a7c01ed47 100644 --- a/build/js/PushMenu.js +++ b/build/js/PushMenu.js @@ -102,41 +102,45 @@ const PushMenu = ($ => { } autoCollapse(resize = false) { - if (this._options.autoCollapseSize) { - if ($(window).width() <= this._options.autoCollapseSize) { - if (!$(Selector.BODY).hasClass(ClassName.OPEN)) { - this.collapse() - } - } else if (resize === true) { - if ($(Selector.BODY).hasClass(ClassName.OPEN)) { - $(Selector.BODY).removeClass(ClassName.OPEN) - } else if ($(Selector.BODY).hasClass(ClassName.CLOSED)) { - this.expand() - } + if (!this._options.autoCollapseSize) { + return + } + + if ($(window).width() <= this._options.autoCollapseSize) { + if (!$(Selector.BODY).hasClass(ClassName.OPEN)) { + this.collapse() + } + } else if (resize === true) { + if ($(Selector.BODY).hasClass(ClassName.OPEN)) { + $(Selector.BODY).removeClass(ClassName.OPEN) + } else if ($(Selector.BODY).hasClass(ClassName.CLOSED)) { + this.expand() } } } remember() { - if (this._options.enableRemember) { - const toggleState = localStorage.getItem(`remember${EVENT_KEY}`) - if (toggleState === ClassName.COLLAPSED) { - if (this._options.noTransitionAfterReload) { - $('body').addClass('hold-transition').addClass(ClassName.COLLAPSED).delay(50).queue(function () { - $(this).removeClass('hold-transition') - $(this).dequeue() - }) - } else { - $('body').addClass(ClassName.COLLAPSED) - } - } else if (this._options.noTransitionAfterReload) { - $('body').addClass('hold-transition').removeClass(ClassName.COLLAPSED).delay(50).queue(function () { + if (!this._options.enableRemember) { + return + } + + const toggleState = localStorage.getItem(`remember${EVENT_KEY}`) + if (toggleState === ClassName.COLLAPSED) { + if (this._options.noTransitionAfterReload) { + $('body').addClass('hold-transition').addClass(ClassName.COLLAPSED).delay(50).queue(function () { $(this).removeClass('hold-transition') $(this).dequeue() }) } else { - $('body').removeClass(ClassName.COLLAPSED) + $('body').addClass(ClassName.COLLAPSED) } + } else if (this._options.noTransitionAfterReload) { + $('body').addClass('hold-transition').removeClass(ClassName.COLLAPSED).delay(50).queue(function () { + $(this).removeClass('hold-transition') + $(this).dequeue() + }) + } else { + $('body').removeClass(ClassName.COLLAPSED) } }