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

Правда или действие #11

Merged
merged 1 commit into from
Jul 22, 2024
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
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h2 class="pictures__title visually-hidden">Фотографии других
<section class="img-upload">
<div class="img-upload__wrapper">
<h2 class="img-upload__title visually-hidden">Загрузка фотографии</h2>
<form class="img-upload__form" id="upload-select-image" autocomplete="off">
<form class="img-upload__form" id="upload-select-image" method="post" enctype="multipart/form-data" action="https://32.javascript.htmlacademy.pro/kekstagram" autocomplete="off">

<!-- Изначальное состояние поля для загрузки изображения -->
<fieldset class="img-upload__start">
Expand Down Expand Up @@ -235,5 +235,6 @@ <h2 class="data-error__title">Не удалось загрузить данны
</section>
</template>
<script src="js/functions.js"></script>
<script src="vendor/pristine/pristine.min.js"></script>
</body>
</html>
57 changes: 57 additions & 0 deletions js/img-upload-form-modal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { isValid } from './img-upload-form-validate';
import { isEscapeKey } from './utils';

const imgUploadform = document.querySelector('.img-upload__form');
const redactForm = document.querySelector('.img-upload__overlay');
const imgUploadInput = document.querySelector('.img-upload__input');
const imgUploadCancelButton = document.querySelector('.img-upload__cancel');
const fieldComments = document.querySelector('.text__description');
const fieldHashtag = document.querySelector('.text__hashtags');


const openRedactForm = () => {
redactForm.classList.remove('hidden');
document.body.classList.add('.modal-open');
document.addEventListener('keydown', onDocumentKeydown);
};

const closeRedactForm = () => {
redactForm.classList.add('.hidden');
document.body.classList.remove('.modal-open');
imgUploadInput.value = '';
document.removeEventListener('keydown', onDocumentKeydown);
};

imgUploadInput.addEventListener('change', () => {
openRedactForm();
});

imgUploadCancelButton.addEventListener('click', () => {
closeRedactForm();
});

function onDocumentKeydown(evt) {
if(isEscapeKey(evt)) {
evt.preventDefault();
closeRedactForm();
}
}

fieldComments.addEventListener('.keydown', (evt) => {
if(isEscapeKey(evt)) {
evt.stopPropagation();
}
});

fieldHashtag.addEventListener('keydown', (evt) => {
if(isEscapeKey(evt)) {
evt.stopPropagation();
}
});

imgUploadform.addEventListener('submit', (evt) => {
if(!isValid()){
evt.preventDefault();
}
});

10 changes: 10 additions & 0 deletions js/img-upload-form-validate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const orderForm = document.querySelector('.img-upload__form');

const pristine = new Pristine(orderForm, {

Check failure on line 3 in js/img-upload-form-validate.js

View workflow job for this annotation

GitHub Actions / Check

'pristine' is assigned a value but never used
classTo: 'form__item',
errorClass: 'form__item--invalid',
successClass: 'form__item--valid',
errorTextParent: 'form__item',
errorTextTag: 'span',
errorTextClass: 'form__error'
});
Loading