Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Фото на память #14

Merged
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
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
Loading