chore(navbar): implemented destroy

This commit is contained in:
Johannes Eder 2021-07-26 18:11:28 +02:00 committed by Sarah Vaupel
parent 74bb9fb548
commit 03b6e199f1

View File

@ -1,4 +1,5 @@
import { Utility } from '../../core/utility';
import { EventManager, EventWrapper, EVENT_TYPE } from '../../lib/event-manager/event-manager';
import './navbar.sass';
import * as throttle from 'lodash.throttle';
@ -18,6 +19,8 @@ export class NavHeaderContainerUtil {
_throttleUpdateWasOpen;
_eventManager;
constructor(element) {
if (!element) {
throw new Error('Navbar Header Container utility needs to be passed an element!');
@ -29,6 +32,9 @@ export class NavHeaderContainerUtil {
this._element = element;
this.radioButton = document.getElementById(`${this._element.id}-radio`);
this._eventManager = new EventManager();
if (!this.radioButton) {
throw new Error('Navbar Header Container utility could not find associated radio button!');
}
@ -58,8 +64,9 @@ export class NavHeaderContainerUtil {
if (!this.container)
return;
window.addEventListener('click', this.clickHandler.bind(this));
this.radioButton.addEventListener('change', this.throttleUpdateWasOpen.bind(this));
const clickEv = new EventWrapper(EVENT_TYPE.CLICK, this.clickHandler.bind(this), window);
const changeEv = new EventWrapper(EVENT_TYPE.CHANGE, this.throttleUpdateWasOpen.bind(this), this.radioButton);
this._eventManager.registerListeners([clickEv, changeEv]);
}
clickHandler() {
@ -81,7 +88,10 @@ export class NavHeaderContainerUtil {
this.wasOpen = this.isOpen();
}
destroy() { /* TODO */ }
destroy() {
this._eventManager.cleanUp();
this._element.classList.remove(HEADER_CONTAINER_INITIALIZED_CLASS);
}
}