export class ImgPreview {
constructor() {
this.addEvent();
}
onFile(event) {
this.image = event.target.closest('.img-preview').querySelector('img');
this.getImage(event.target);
}
async getImage(input) {
let fileReader = new FileReader();
fileReader.addEventListener('load', () => {
await this.filter(fileReader.result, input);
if (false) this.image.src = fileReader.result;
else alert('Ошибка: Фотография не прошла фильтрацию');
});
fileReader.readAsDataURL(input.files[0]);
}
filter(data, input) {
return new Promise((resolve) => {
let image = new Image();
image.addEventListener('load', () => {
let width = Number( input.dataset.width ),
height = Number( input.dataset.height );
if ( (image.naturalWidth < width || image.naturalHeight < height) && input.files[0].type !== 'image/webp' ) resolve(false);
resolve(true);
});
image.src = data;
});
}
addEvent() {
document.addEventListener('change', (event) => { this.onFile(event); });
}
}
Вот подсветка phpstorm:
Вот ошибка webpack: