diff --git a/assets/index.ts b/assets/index.ts index ccfadf044..0282e0a7c 100644 --- a/assets/index.ts +++ b/assets/index.ts @@ -9,21 +9,27 @@ const element = document.getElementById('nav'); const pinButton = document.getElementById('pin-btn'); if (pinButton != null) { - pinButton.onclick = handleNavExpanded; + pinButton.addEventListener('click', () => { + handleNavToggle(); + }); } if (sessionStorage.getItem('navigation-pinned')) { - handleNavExpanded(); + handleNavToggle(); } -function handleNavExpanded() { - if (element?.classList.contains('nav-block--pinned')) { +function handleNavToggle() { + if (element == null || pinButton == null) { + return null; + } + + if (element.classList.contains('nav-block--pinned')) { sessionStorage.removeItem('navigation-pinned'); element.classList.remove('nav-block--pinned'); - pinButton?.setAttribute('title', gettext('Expand')); + pinButton.setAttribute('title', gettext('Expand')); } else { sessionStorage.setItem('navigation-pinned', 'true'); - element?.classList.add('nav-block--pinned'); - pinButton?.setAttribute('title', gettext('Collapse')); + element.classList.add('nav-block--pinned'); + pinButton.setAttribute('title', gettext('Collapse')); } }