Merge pull request #5015 from burdittw/v4-dev-check-for-sidebar

Issue 5011- Add checks for if sidebar exists to stop errors on pages with no sidebar
pull/5026/head
Daniel 2 years ago committed by GitHub
commit c8869e768b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,16 +21,18 @@ const distPath = (path != undefined) ? path : '../../../dist'
const SELECTOR_SIDEBAR_WRAPPER = '.sidebar-wrapper' const SELECTOR_SIDEBAR_WRAPPER = '.sidebar-wrapper'
const Default = { const Default = {
scrollbarTheme: 'os-theme-light', scrollbarTheme: 'os-theme-light',
scrollbarAutoHide: 'leave' scrollbarAutoHide: 'leave',
scrollbarClickScroll: true
} }
document.addEventListener("DOMContentLoaded", function() { document.addEventListener("DOMContentLoaded", function() {
if (typeof OverlayScrollbarsGlobal?.OverlayScrollbars !== 'undefined') { const sidebarWrapper = document.querySelector(SELECTOR_SIDEBAR_WRAPPER)
OverlayScrollbarsGlobal.OverlayScrollbars(document.querySelector(SELECTOR_SIDEBAR_WRAPPER), { if (sidebarWrapper && typeof OverlayScrollbarsGlobal?.OverlayScrollbars !== 'undefined') {
OverlayScrollbarsGlobal.OverlayScrollbars(sidebarWrapper, {
scrollbars: { scrollbars: {
theme: Default.scrollbarTheme, theme: Default.scrollbarTheme,
autoHide: Default.scrollbarAutoHide, autoHide: Default.scrollbarAutoHide,
clickScroll: true clickScroll: Default.scrollbarClickScroll
} }
}) })
} }

@ -29,6 +29,7 @@ const CLASS_NAME_SIDEBAR_EXPAND = 'sidebar-expand'
const CLASS_NAME_SIDEBAR_OVERLAY = 'sidebar-overlay' const CLASS_NAME_SIDEBAR_OVERLAY = 'sidebar-overlay'
const CLASS_NAME_MENU_OPEN = 'menu-open' const CLASS_NAME_MENU_OPEN = 'menu-open'
const SELECTOR_APP_SIDEBAR = '.app-sidebar'
const SELECTOR_SIDEBAR_WRAPPER = '.sidebar-wrapper' const SELECTOR_SIDEBAR_WRAPPER = '.sidebar-wrapper'
const SELECTOR_SIDEBAR_MENU = '.sidebar-menu' const SELECTOR_SIDEBAR_MENU = '.sidebar-menu'
const SELECTOR_NAV_ITEM = '.nav-item' const SELECTOR_NAV_ITEM = '.nav-item'
@ -151,12 +152,16 @@ class PushMenu {
*/ */
domReady(() => { domReady(() => {
const data = new PushMenu(document.body, Defaults) const sidebar = document?.querySelector(SELECTOR_APP_SIDEBAR) as HTMLElement | undefined
data.init()
window.addEventListener('resize', () => { if (sidebar) {
const data = new PushMenu(sidebar, Defaults)
data.init() data.init()
})
window.addEventListener('resize', () => {
data.init()
})
}
const sidebarOverlay = document.createElement('div') const sidebarOverlay = document.createElement('div')
sidebarOverlay.className = CLASS_NAME_SIDEBAR_OVERLAY sidebarOverlay.className = CLASS_NAME_SIDEBAR_OVERLAY

Loading…
Cancel
Save