1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
2// See the LICENCE file in the repository root for full licence text.
3
4export default class SidebarToggle {
5 private readonly menuWrapper: Element;
6 private readonly navButton: Element;
7
8 constructor() {
9 const navButton = document.getElementById('nav-button');
10 const menuWrapper = document.querySelector('.tocify-wrapper');
11
12 if (navButton == null || menuWrapper == null) {
13 throw new Error('nav button and/or menu wrapper is missing');
14 }
15
16 this.navButton = navButton;
17 this.menuWrapper = menuWrapper;
18
19 this.navButton.addEventListener('click', this.onClickNavButton);
20 }
21
22 private readonly onClickNavButton = (e: MouseEvent) => {
23 e.preventDefault();
24 this.menuWrapper.classList.toggle('open');
25 this.navButton.classList.toggle('open');
26 };
27}