Return early.

pull/2751/head
XhmikosR 2020-05-31 16:45:54 +03:00
parent 3528b6c1f8
commit 187a01a8ee
3 changed files with 111 additions and 101 deletions

View File

@ -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
}
})
}
})
}
}

View File

@ -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
}
})
}
}

View File

@ -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)
}
}