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