Add checks for if sidebar exists

Added checks to some scripting to check if a sidebar exists before trying to load some code that affects the sidebar and throws console errors because there was no sidebar on the page.
pull/5015/head
Walter Burditt 2023-04-01 14:58:32 -07:00
parent ec3d689ea1
commit 9625827c3a
2 changed files with 55 additions and 47 deletions

View File

@ -18,6 +18,7 @@ const distPath = (path != undefined) ? path : '../../../dist'
<!-- OPTIONAL SCRIPTS -->
<script is:inline>
const SELECTOR_APP_SIDEBAR = '.app-sidebar'
const SELECTOR_SIDEBAR_WRAPPER = '.sidebar-wrapper'
const Default = {
scrollbarTheme: 'os-theme-light',
@ -25,6 +26,7 @@ const distPath = (path != undefined) ? path : '../../../dist'
}
document.addEventListener("DOMContentLoaded", function() {
if (document.querySelector(SELECTOR_APP_SIDEBAR)) {
if (typeof OverlayScrollbarsGlobal?.OverlayScrollbars !== 'undefined') {
OverlayScrollbarsGlobal.OverlayScrollbars(document.querySelector(SELECTOR_SIDEBAR_WRAPPER), {
scrollbars: {
@ -34,5 +36,6 @@ const distPath = (path != undefined) ? path : '../../../dist'
}
})
}
}
})
</script>

View File

@ -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'
@ -151,6 +152,9 @@ class PushMenu {
*/
domReady(() => {
const sidebar = document.querySelector(SELECTOR_APP_SIDEBAR)
if (sidebar) {
const data = new PushMenu(document.body, Defaults)
data.init()
@ -194,6 +198,7 @@ domReady(() => {
}
})
})
}
})
export default PushMenu