Skip to content

Commit

Permalink
Merge pull request #14 from PavelUd/module12-task2
Browse files Browse the repository at this point in the history
  • Loading branch information
keksobot committed Dec 22, 2023
2 parents d3142b3 + fa2327c commit 7322bbf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ <h2 class="img-upload__title visually-hidden">Загрузка фотограф

<!-- Изначальное состояние поля для загрузки изображения -->
<fieldset class="img-upload__start">
<input type="file" id="upload-file" class="img-upload__input visually-hidden" name="filename" required>
<input type="file" id="upload-file" class="img-upload__input visually-hidden" name="filename" accept="image/png, image/jpeg, image/jpg, image/gif" required>
<label for="upload-file" class="img-upload__label img-upload__control">Загрузить</label>
</fieldset>

Expand Down
19 changes: 11 additions & 8 deletions js/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import{createEffectSlider, onEffectsFilterChange, resetFilters} from './image-ef
const MAX_HASHTAG_LENGTH = 20;
const MAX_COMMENT_LENGTH = 140;
const MAX_HASHTAG_COUNT = 5;
const VALID_IMAGE_TYPES = ['image/gif', 'image/jpeg', 'image/png'];
const HASHTAG_RULE = /^#[А-яа-яA-za-zёЁ]{1,19}$/;
const ErrorMessage = {
BAD_HASHTAG: 'Уникальные хештеги, каждый не более 20 символов, должны быть разделены пробелом',
Expand All @@ -17,6 +16,8 @@ const ErrorMessage = {
const uploadButton = document.querySelector('#upload-file');
const form = document.querySelector('.img-upload__form');
const overlay = document.querySelector('.img-upload__overlay');
const mainImage = overlay.querySelector('.img-upload__preview img');
const effectsPreviews = overlay.querySelectorAll('.effects__item .effects__preview');
const cancelButton = document.querySelector('#upload-cancel');
const hashtags = document.querySelector('.text__hashtags');
const comments = document.querySelector('.text__description');
Expand Down Expand Up @@ -63,12 +64,6 @@ const onCancelButtonClick = () => {
closeOverlay();
};

const isPicture = () => {
const fileType = uploadButton.files[0].type;

return VALID_IMAGE_TYPES.some((type) => type === fileType);
};

const blockSubmitButton = () => {
submitButton.disabled = true;
submitButton.textContent = SubmitButtonText.SENDING;
Expand Down Expand Up @@ -118,8 +113,16 @@ function closeOverlay () {
form.reset();
}

const uploadFile = () => {
const file = uploadButton.files[0];
mainImage.src = mainImage.src = URL.createObjectURL(file);
effectsPreviews.forEach((picture) => {
picture.style.backgroundImage = `url('${mainImage.src}')`;
});
};

const onUploadButtonChange = () => {
if(!isPicture()) {return;}
uploadFile();
overlay.classList.remove('hidden');
document.body.classList.add('modal-open');
form.addEventListener('submit', onFormSubmit);
Expand Down

0 comments on commit 7322bbf

Please sign in to comment.