Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function () {
- /* Можно лучше:
- Вынести массив с начальными карточками в отдельный файл, например cards.js
- */
- const initialCards = [{
- name: 'Архыз',
- link: 'https://pictures.s3.yandex.net/frontend-developer/cards-compressed/arkhyz.jpg'
- },
- {
- name: 'Челябинская область',
- link: 'https://pictures.s3.yandex.net/frontend-developer/cards-compressed/chelyabinsk-oblast.jpg'
- },
- {
- name: 'Иваново',
- link: 'https://pictures.s3.yandex.net/frontend-developer/cards-compressed/ivanovo.jpg'
- },
- {
- name: 'Камчатка',
- link: 'https://pictures.s3.yandex.net/frontend-developer/cards-compressed/kamchatka.jpg'
- },
- {
- name: 'Холмогорский район',
- link: 'https://pictures.s3.yandex.net/frontend-developer/cards-compressed/kholmogorsky-rayon.jpg'
- },
- {
- name: 'Байкал',
- link: 'https://pictures.s3.yandex.net/frontend-developer/cards-compressed/baikal.jpg'
- },
- {
- name: 'Нургуш',
- link: 'https://pictures.s3.yandex.net/frontend-developer/cards-compressed/khrebet-nurgush.jpg'
- },
- {
- name: 'Тулиновка',
- link: 'https://pictures.s3.yandex.net/frontend-developer/cards-compressed/tulinovka.jpg'
- },
- {
- name: 'Остров Желтухина',
- link: 'https://pictures.s3.yandex.net/frontend-developer/cards-compressed/zheltukhin-island.jpg'
- },
- {
- name: 'Владивосток',
- link: 'https://pictures.s3.yandex.net/frontend-developer/cards-compressed/vladivostok.jpg'
- }
- ];
- const cardsContainer = document.querySelector('.places-list.root__section');
- /* Можно лучше:
- Код-стайл: назвать перменные editProfilePopup, imagePopup и newCardPopup
- */
- const divPopupEditProfile = document.querySelector('div.popup.root__about');
- const divPopupImage = document.querySelector('div.root__image');
- const divPopupNewCard = document.querySelector('div.root__new-card');
- const userNameHTML = document.querySelector('h1.user-info__name');
- const userAboutHTML = document.querySelector('p.user-info__job');
- const formNewCardValidator = new FormValidator(divPopupNewCard);
- const formEditValidator = new FormValidator(divPopupEditProfile);
- const newCardPopup = new NewCardPopup(divPopupNewCard);
- const userInfo = new UserInfo(userNameHTML, userAboutHTML);
- const editProfilePopup = new EditProfilePopup(divPopupEditProfile, userInfo, userNameHTML, userAboutHTML);
- const imagePopup = new ImagePopup(divPopupImage);
- const cardElements = [];
- /* Можно лучше:
- Использовать forEach
- */
- for (let i = 0; i < initialCards.length; i++) {
- const card = createCard(initialCards[i].name, initialCards[i].link);
- /* Надо исправить:
- Для загрузки начальных карточек на страницу использовать метод render экземпляра класса CardList
- */
- cardElements.push(card);
- }
- /* Надо исправить:
- Вторым параметром cardList должен принимать массив с начальными карточками, а не пустой массив cardElements
- */
- const cardlist = new CardList(cardsContainer, cardElements);
- cardlist.render();
- document.querySelector('.button.user-info__edit').addEventListener('click', () => {
- editProfilePopup.open();
- formEditValidator.resetErrorrs();
- });
- document.querySelector('.button.user-info__button').addEventListener('click', () => {
- newCardPopup.open();
- formNewCardValidator.resetErrorrs();
- });
- newCardPopup.popup.addEventListener('submit', e => {
- e.preventDefault();
- const card = createCard(newCardPopup.userCardName.value, newCardPopup.userCardURL.value);
- cardlist.addCard(card);
- newCardPopup.close();
- });
- function createCard(name, link) {
- const card = new Card(name, link);
- const cardElement = card.create();
- card.setEventListeners();
- card.image.addEventListener('click', () => {
- imagePopup.open(card.imageUrl);
- });
- return cardElement;
- }
- })();
- /* REVIEW:
- Большинство ошибок были исправлены, отличная работа! Остлось внести небольшие доработки и работа будет принята.
- Надо исправить:
- - При удалении карточки необходимо также удалять обработчики событий с её элементов
- - Метод render необходимо вызывать не в в конструкторе класса CardList, а после создания экземпляра класса в index.js
- (для загрузки начальных карточек на страницу использовать метод render экземпляра класса CardList)
- - Вторым параметром cardList должен принимать массив с начальными карточками, а не пустой массив cardElements
- В остальном, отличная работа. Желаю Вам хорошего дня!
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement