UNPKG

stylescape

Version:

Stylescape is a visual identity framework developed by Scape Agency.

61 lines 2.34 kB
import { StateManager } from "../state/StateManager.js"; import { LocalStorageManager } from "../storage/LocalStorageManager.js"; export class AsideHandler { constructor(menuId, switchId) { this.asideMenu = null; this.asideSwitch = null; this.asideMenuActive = AsideHandler.HIDDEN_STATE; this.localStorageManager = LocalStorageManager.getInstance(); this.stateManager = new StateManager(); this.menuId = menuId; this.switchId = switchId; this.assertMenu(); this.setupToggleListener(); this.updateStateMenu(); } assertMenu() { this.asideMenu = document.getElementById(this.menuId); this.asideSwitch = document.getElementById(this.switchId); } setupToggleListener() { if (this.asideSwitch) { this.asideSwitch.addEventListener("click", () => this.toggleMenu()); } } toggleMenu() { var _a; this.assertMenu(); if ((_a = this.asideMenu) === null || _a === void 0 ? void 0 : _a.classList.contains(AsideHandler.VISIBLE_CLASS)) { this.hideMenu(); } else { this.showMenu(); } } showMenu() { this.assertMenu(); this.localStorageManager.setValue(this.menuId + AsideHandler.VISIBLE_SUFFIX, AsideHandler.VISIBLE_STATE); this.updateStateMenu(); } hideMenu() { this.assertMenu(); this.localStorageManager.setValue(this.menuId + AsideHandler.VISIBLE_SUFFIX, AsideHandler.HIDDEN_STATE); this.updateStateMenu(); } updateStateMenu() { var _a; this.assertMenu(); if (!this.asideMenu) return; this.asideMenuActive = this.localStorageManager.getValue(this.menuId + AsideHandler.VISIBLE_SUFFIX) || this.asideMenuActive; const isVisible = this.asideMenuActive === AsideHandler.VISIBLE_STATE; this.asideMenu.classList.toggle(AsideHandler.VISIBLE_CLASS, isVisible); (_a = this.asideSwitch) === null || _a === void 0 ? void 0 : _a.classList.toggle(AsideHandler.VISIBLE_CLASS, isVisible); } } AsideHandler.VISIBLE_CLASS = "active"; AsideHandler.VISIBLE_SUFFIX = "_visibility"; AsideHandler.VISIBLE_STATE = "show"; AsideHandler.HIDDEN_STATE = "hide"; //# sourceMappingURL=AsideHandler.js.map