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
12 changes: 6 additions & 6 deletions js/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,27 @@ const onHandleEscapeKey = (evt) => {
}
};

const onEscPress = (evt) => {
function onEscPress(evt) {
if (evt.key === 'Escape') {

onCloseSuccessModal();
onCloseErrorModal();
}
};
}

const onOutsideClick = (evt) => {
function onOutsideClick(evt) {
if (!evt.target.closest('.success__inner')) {
onCloseSuccessModal();
}
};
}

const pristine = new Pristine (form, {
classTo: 'img-upload__field-wrapper',
errorTextParent: 'img-upload__field-wrapper',
errorTextClass: 'img-upload__field-wrapper--error',
}, false);

const resetForm = () => {
function resetForm() {
form.reset();
pristine.reset();

Expand All @@ -110,7 +110,7 @@ const resetForm = () => {
if (effectLevel) {
effectLevel.classList.add('hidden');
}
};
}


formOpener.addEventListener('click', () => {
Expand Down
37 changes: 18 additions & 19 deletions js/picture-from-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ const bigPicture = document.querySelector('.big-picture__img');
const closeBigPicture = document.querySelector('.big-picture__cancel');
const showMoreComments = openBigPicture.querySelector('.social__comments-loader');

const showDataError = (method) => {

const errorElement = errorTemplate.content.cloneNode(true);
errorElement.querySelector('h2').textContent = ErrorText[method];

document.body.appendChild(errorElement);

setTimeout(() => {
const errorSection = document.querySelector('.data-error');
if (errorSection) {
errorSection.remove();
}
}, 5000);
};

export const renderPhotos = (picture) => {
const template = photoTemplate.cloneNode(true);
Expand Down Expand Up @@ -51,21 +65,6 @@ export const onLoadRenderPhotos = async () => {
}
};

const showDataError = (method) => {

const errorElement = errorTemplate.content.cloneNode(true);
errorElement.querySelector('h2').textContent = ErrorText[method];

document.body.appendChild(errorElement);

setTimeout(() => {
const errorSection = document.querySelector('.data-error');
if (errorSection) {
errorSection.remove();
}
}, 5000);
};

document.addEventListener('DOMContentLoaded', onLoadRenderPhotos);

const onHandleEscapeKey = (evt) => {
Expand All @@ -80,7 +79,7 @@ const changeEventListeners = (action) => {
closeBigPicture[method]('click', closeModal);
};

const closeModal = () => {
function closeModal() {
openBigPicture.classList.add('hidden');
document.querySelector('body').classList.remove('modal-open');

Expand All @@ -90,7 +89,7 @@ const closeModal = () => {
showMoreComments.removeEventListener('click', onCurrentLoadMoreHandler);
onCurrentLoadMoreHandler = null;
}
};
}

const renderComments = (comments, commentList, fragment) => {
comments.forEach((comment) => {
Expand All @@ -107,7 +106,7 @@ const renderComments = (comments, commentList, fragment) => {
});
return fragment;
};
export const onClickOpenModal = (thumbnail) => {
export function onClickOpenModal(thumbnail) {
if (onCurrentLoadMoreHandler) {
showMoreComments.removeEventListener('click', onCurrentLoadMoreHandler);
onCurrentLoadMoreHandler = null;
Expand Down Expand Up @@ -173,4 +172,4 @@ export const onClickOpenModal = (thumbnail) => {
showMoreComments.addEventListener('click', onCurrentLoadMoreHandler);
}
changeEventListeners('add');
};
}
6 changes: 3 additions & 3 deletions js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ const getCommentName = (name, surname) => {
};

const generateComment = () => {
let comment;

const id = getUniqueRandom(usedCommentId, 1, 750, 'Не могу найти уникальный ID комментария после 750 попыток');

comment = {
const commentBody = {
commentId: id,
commentUrl: `img/avatar-${getRandomInteger(1, 6)}.svg`,
commentMessage: getCommentMessage(),
commentName: getCommentName(NAMES, SURNAMES)
};

return comment
return commentBody;
};

const comments = (amount) => {
Expand Down