chore(file-input): implemented destroy

This commit is contained in:
Johannes Eder 2021-07-20 11:10:21 +02:00 committed by Sarah Vaupel
parent dedbab689f
commit 8cb3a41fcb

View File

@ -1,4 +1,5 @@
import { Utility } from '../../core/utility';
import { EventManager, EventWrapper, EVENT_TYPE } from '../../lib/event-manager/event-manager';
import './file-input.sass';
const FILE_INPUT_CLASS = 'file-input';
@ -19,6 +20,8 @@ export class FileInput {
_fileList;
_label;
_eventManager;
constructor(element, app) {
if (!element) {
throw new Error('FileInput utility cannot be setup without an element!');
@ -27,6 +30,8 @@ export class FileInput {
this._element = element;
this._app = app;
this._eventManager = new EventManager();
if (this._element.classList.contains(FILE_INPUT_INITIALIZED_CLASS)) {
throw new Error('FileInput utility already initialized!');
}
@ -40,11 +45,11 @@ export class FileInput {
this._label = this._createFileLabel();
this._updateLabel();
// add change listener
this._element.addEventListener('change', () => {
const changeInputEv = new EventWrapper(EVENT_TYPE.CHANGE,(() => {
this._updateLabel();
this._renderFileList();
});
}).bind(this), this._element );
this._eventManager.registerNewListener(changeInputEv);
// add util class for styling and mark as initialized
this._element.classList.add(FILE_INPUT_CLASS);
@ -52,7 +57,9 @@ export class FileInput {
}
destroy() {
// TODO
this._fileList.remove();
this._label.remove();
this._element.classList.remove(FILE_INPUT_INITIALIZED_CLASS);
}
_renderFileList() {