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.
This commit is contained in:
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,14 +26,16 @@ const distPath = (path != undefined) ? path : '../../../dist'
}
document.addEventListener("DOMContentLoaded", function() {
if (typeof OverlayScrollbarsGlobal?.OverlayScrollbars !== 'undefined') {
OverlayScrollbarsGlobal.OverlayScrollbars(document.querySelector(SELECTOR_SIDEBAR_WRAPPER), {
scrollbars: {
theme: Default.scrollbarTheme,
autoHide: Default.scrollbarAutoHide,
clickScroll: true
}
})
if (document.querySelector(SELECTOR_APP_SIDEBAR)) {
if (typeof OverlayScrollbarsGlobal?.OverlayScrollbars !== 'undefined') {
OverlayScrollbarsGlobal.OverlayScrollbars(document.querySelector(SELECTOR_SIDEBAR_WRAPPER), {
scrollbars: {
theme: Default.scrollbarTheme,
autoHide: Default.scrollbarAutoHide,
clickScroll: true
}
})
}
}
})
</script>