chore(interactive-fieldset): implemented destroy method

This commit is contained in:
Johannes Eder 2021-07-08 15:53:42 +02:00 committed by Sarah Vaupel
parent 266ceea5a8
commit 40283e348b

View File

@ -1,4 +1,5 @@
import { Utility } from '../../core/utility';
import { EventManager, EventWrapper, EVENT_TYPE } from '../../lib/event-manager/event-manager';
const INTERACTIVE_FIELDSET_UTIL_TARGET_SELECTOR = '.interactive-fieldset__target';
@ -15,6 +16,8 @@ export class InteractiveFieldset {
_element;
_eventManager;
conditionalInput;
conditionalValue;
target;
@ -28,6 +31,8 @@ export class InteractiveFieldset {
this._element = element;
this._eventManger = new EventManager();
if (this._element.classList.contains(INTERACTIVE_FIELDSET_INITIALIZED_CLASS)) {
return false;
}
@ -62,13 +67,11 @@ export class InteractiveFieldset {
this.childInputs = Array.from(this._element.querySelectorAll(INTERACTIVE_FIELDSET_CHILD_SELECTOR)).filter(child => child.closest('[uw-interactive-fieldset]') === this._element);
// add event listener
const observer = new MutationObserver(this._updateVisibility.bind(this));
observer.observe(this.conditionalInput, { attributes: true, attributeFilter: ['data-interactive-fieldset-hidden'] });
this.conditionalInput.addEventListener('input', this._updateVisibility.bind(this));
this._eventManager.registerNewMutationObserver(this._updateVisibility.bind(this), this.conditionalInput, { attributes: true, attributeFilter: ['data-interactive-fieldset-hidden'] });
const inputEvent = new EventWrapper(EVENT_TYPE.INPUT, this._updateVisibility.bind(this), this.conditionalInput);
this._eventManager.registerNewListener(inputEvent);
// mark as initialized
this._element.classList.add(INTERACTIVE_FIELDSET_INITIALIZED_CLASS);
}
start() {
@ -77,7 +80,8 @@ export class InteractiveFieldset {
}
destroy() {
// TODO
this._eventManager.cleanUp();
this._element.classList.remove(INTERACTIVE_FIELDSET_INITIALIZED_CLASS);
}
_updateVisibility() {