diff --git a/frontend/src/lib/event-manager/event-manager.js b/frontend/src/lib/event-manager/event-manager.js index 03a798308..edc97c91f 100644 --- a/frontend/src/lib/event-manager/event-manager.js +++ b/frontend/src/lib/event-manager/event-manager.js @@ -10,6 +10,7 @@ export const EVENT_TYPE = { INPUT : 'input', FOCUS_OUT : 'focusout', BEFOREUNLOAD : 'beforeunload', + HASH_CHANGE : 'hashchange', }; diff --git a/frontend/src/utils/show-hide/show-hide.js b/frontend/src/utils/show-hide/show-hide.js index 3419ee1f4..e7f7c3315 100644 --- a/frontend/src/utils/show-hide/show-hide.js +++ b/frontend/src/utils/show-hide/show-hide.js @@ -1,5 +1,6 @@ import { Utility } from '../../core/utility'; import { StorageManager, LOCATION } from '../../lib/storage-manager/storage-manager'; +import { EventManager, EventWrapper, EVENT_TYPE } from '../../lib/event-manager/event-manager'; import './show-hide.sass'; const SHOW_HIDE_LOCAL_STORAGE_KEY = 'SHOW_HIDE'; @@ -16,6 +17,7 @@ export class ShowHide { _showHideId; _element; + _eventManager; _storageManager = new StorageManager(SHOW_HIDE_LOCAL_STORAGE_KEY, '1.0.0', { location: LOCATION.LOCAL }); constructor(element) { @@ -24,13 +26,15 @@ export class ShowHide { } this._element = element; + this._eventManager = new EventManager(); if (this._element.classList.contains(SHOW_HIDE_INITIALIZED_CLASS)) { return false; } // register click listener - this._addClickListener(); + const clickEv = new EventWrapper(EVENT_TYPE.CLICK, this._clickHandler.bind(this), this._element); + this._eventManager.registerNewListener(clickEv); // param showHideId if (this._element.dataset.showHideId) { @@ -58,17 +62,19 @@ export class ShowHide { } this._checkHash(); - - window.addEventListener('hashchange', this._checkHash.bind(this)); + const hashChangeEv = new EventWrapper(EVENT_TYPE.HASH_CHANGE, this._checkHash.bind(this), window); + this._eventManager.registerNewListener(hashChangeEv); // mark as initialized this._element.classList.add(SHOW_HIDE_INITIALIZED_CLASS, SHOW_HIDE_TOGGLE_CLASS); } - destroy() {} - - _addClickListener() { - this._element.addEventListener('click', this._clickHandler.bind(this)); + destroy() { + this._eventManager.cleanUp(); + this._storageManager.clear(); + if(this._element.parentElement.contains(SHOW_HIDE_COLLAPSED_CLASS)) + this._element.parentElement.classList.remove(SHOW_HIDE_COLLAPSED_CLASS); + this._element.classList.remove(SHOW_HIDE_INITIALIZED_CLASS, SHOW_HIDE_TOGGLE_CLASS); } _show() {