Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions js/upload-image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const FILE_TYPES = ['jpg', 'jpeg', 'png'];

const imagePreviewWrapper = document.querySelector('.img-upload__preview');
const imagePreview = imagePreviewWrapper.querySelector('img');

const handleUpload = (target) => {
const file = target.files[0];
const fileName = file.name.toLowerCase();

const matches = FILE_TYPES.some((it) => fileName.endsWith(it));

if(matches) {
imagePreview.src = URL.createObjectURL(file);
}
};

export {
handleUpload,
};
7 changes: 6 additions & 1 deletion js/upload-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { checkValidaty } from './form-validation.js';
import { resetEffects } from './effects.js';
import { postPhoto } from './api.js';
import { showPostSuccessMessage } from './messages.js';
import {handleUpload} from './upload-image.js';

const modalWindow = document.querySelector('.img-upload__overlay');
const uploadForm = document.querySelector('.img-upload__form');
Expand All @@ -13,11 +14,15 @@ const modalCloseButton = document.querySelector('.img-upload__cancel');
const hashTagsInput = document.querySelector('.text__hashtags');
const descriptionInput = document.querySelector('.text__description');


uploadForm.method = 'post';
uploadForm.action = 'https://31.javascript.htmlacademy.pro/kekstagram';
uploadForm.enctype = 'multipart/form-data';

const onUploadClick = () => handleOpen();
const onUploadClick = ({target}) => {
handleUpload(target);
handleOpen();
};
const onEscapeKeydown = (evt) => {
if (document.activeElement === hashTagsInput
||
Expand Down
Loading