Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 5011- Add checks for if sidebar exists to stop errors on pages with no sidebar #5015

Merged
merged 2 commits into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/html/components/_scripts.astro
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ const distPath = (path != undefined) ? path : '../../../dist'
const SELECTOR_SIDEBAR_WRAPPER = '.sidebar-wrapper'
const Default = {
scrollbarTheme: 'os-theme-light',
scrollbarAutoHide: 'leave'
scrollbarAutoHide: 'leave',
scrollbarClickScroll: true
}

document.addEventListener("DOMContentLoaded", function() {
if (typeof OverlayScrollbarsGlobal?.OverlayScrollbars !== 'undefined') {
OverlayScrollbarsGlobal.OverlayScrollbars(document.querySelector(SELECTOR_SIDEBAR_WRAPPER), {
const sidebarWrapper = document.querySelector(SELECTOR_SIDEBAR_WRAPPER)
if (sidebarWrapper && typeof OverlayScrollbarsGlobal?.OverlayScrollbars !== 'undefined') {
OverlayScrollbarsGlobal.OverlayScrollbars(sidebarWrapper, {
scrollbars: {
theme: Default.scrollbarTheme,
autoHide: Default.scrollbarAutoHide,
clickScroll: true
clickScroll: Default.scrollbarClickScroll
}
})
}
Expand Down
13 changes: 9 additions & 4 deletions src/ts/push-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const CLASS_NAME_SIDEBAR_EXPAND = 'sidebar-expand'
const CLASS_NAME_SIDEBAR_OVERLAY = 'sidebar-overlay'
const CLASS_NAME_MENU_OPEN = 'menu-open'

const SELECTOR_APP_SIDEBAR = '.app-sidebar'
const SELECTOR_SIDEBAR_WRAPPER = '.sidebar-wrapper'
const SELECTOR_SIDEBAR_MENU = '.sidebar-menu'
const SELECTOR_NAV_ITEM = '.nav-item'
Expand Down Expand Up @@ -151,12 +152,16 @@ class PushMenu {
*/

domReady(() => {
const data = new PushMenu(document.body, Defaults)
data.init()
const sidebar = document?.querySelector(SELECTOR_APP_SIDEBAR) as HTMLElement | undefined

window.addEventListener('resize', () => {
if (sidebar) {
const data = new PushMenu(sidebar, Defaults)
data.init()
})

window.addEventListener('resize', () => {
data.init()
})
}

const sidebarOverlay = document.createElement('div')
sidebarOverlay.className = CLASS_NAME_SIDEBAR_OVERLAY
Expand Down