diff --git a/js/load-pictures.js b/js/load-pictures.js index 8b13789..fb27366 100644 --- a/js/load-pictures.js +++ b/js/load-pictures.js @@ -1 +1,19 @@ +import { FILE_TYPES } from './constant.js'; +const imgUploadPreview = document.querySelector('.img-upload__preview img'); +const fileChooser = document.querySelector('.img-upload__start input[type=file]'); + +const loadingPicture = () => { + fileChooser.addEventListener('change', () => { + const file = fileChooser.files[0]; + const fileName = file.name.toLowerCase(); + + const matches = FILE_TYPES.some((it) => fileName.endsWith(it)); + + if (matches) { + imgUploadPreview.src = URL.createObjectURL(file); + } + }); +}; + +export { loadingPicture };