Advertisement
VanGreed

#8

Jul 13th, 2020
682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function () {
  2.   /* Можно лучше:
  3.   Вынести массив с начальными карточками в отдельный файл, например cards.js
  4.   */
  5.   const initialCards = [{
  6.           name: 'Архыз',
  7.           link: 'https://pictures.s3.yandex.net/frontend-developer/cards-compressed/arkhyz.jpg'
  8.       },
  9.       {
  10.           name: 'Челябинская область',
  11.           link: 'https://pictures.s3.yandex.net/frontend-developer/cards-compressed/chelyabinsk-oblast.jpg'
  12.       },
  13.       {
  14.           name: 'Иваново',
  15.           link: 'https://pictures.s3.yandex.net/frontend-developer/cards-compressed/ivanovo.jpg'
  16.       },
  17.       {
  18.           name: 'Камчатка',
  19.           link: 'https://pictures.s3.yandex.net/frontend-developer/cards-compressed/kamchatka.jpg'
  20.       },
  21.       {
  22.           name: 'Холмогорский район',
  23.           link: 'https://pictures.s3.yandex.net/frontend-developer/cards-compressed/kholmogorsky-rayon.jpg'
  24.       },
  25.       {
  26.           name: 'Байкал',
  27.           link: 'https://pictures.s3.yandex.net/frontend-developer/cards-compressed/baikal.jpg'
  28.       },
  29.       {
  30.           name: 'Нургуш',
  31.           link: 'https://pictures.s3.yandex.net/frontend-developer/cards-compressed/khrebet-nurgush.jpg'
  32.       },
  33.       {
  34.           name: 'Тулиновка',
  35.           link: 'https://pictures.s3.yandex.net/frontend-developer/cards-compressed/tulinovka.jpg'
  36.       },
  37.       {
  38.           name: 'Остров Желтухина',
  39.           link: 'https://pictures.s3.yandex.net/frontend-developer/cards-compressed/zheltukhin-island.jpg'
  40.       },
  41.       {
  42.           name: 'Владивосток',
  43.           link: 'https://pictures.s3.yandex.net/frontend-developer/cards-compressed/vladivostok.jpg'
  44.       }
  45.   ];
  46.  
  47.   const cardsContainer = document.querySelector('.places-list.root__section');
  48.   /* Можно лучше:
  49.   Код-стайл: назвать перменные editProfilePopup, imagePopup и newCardPopup
  50.   */
  51.   const divPopupEditProfile = document.querySelector('div.popup.root__about');
  52.   const divPopupImage = document.querySelector('div.root__image');
  53.   const divPopupNewCard = document.querySelector('div.root__new-card');
  54.   const userNameHTML = document.querySelector('h1.user-info__name');
  55.   const userAboutHTML = document.querySelector('p.user-info__job');
  56.  
  57.  
  58.   const formNewCardValidator = new FormValidator(divPopupNewCard);
  59.   const formEditValidator = new FormValidator(divPopupEditProfile);
  60.   const newCardPopup = new NewCardPopup(divPopupNewCard);
  61.   const userInfo = new UserInfo(userNameHTML, userAboutHTML);
  62.   const editProfilePopup = new EditProfilePopup(divPopupEditProfile, userInfo, userNameHTML, userAboutHTML);
  63.   const imagePopup = new ImagePopup(divPopupImage);
  64.  
  65.   const cardElements = [];
  66.  
  67.   /* Можно лучше:
  68.   Использовать forEach
  69.   */
  70.   for (let i = 0; i < initialCards.length; i++) {
  71.       const card = createCard(initialCards[i].name, initialCards[i].link);
  72.       /* Надо исправить:
  73.  
  74.       Для загрузки начальных карточек на страницу использовать метод render экземпляра класса CardList
  75.       */
  76.       cardElements.push(card);
  77.   }
  78.  
  79.   /* Надо исправить:
  80.  
  81.   Вторым параметром cardList должен принимать массив с начальными карточками, а не пустой массив cardElements
  82.   */
  83.   const cardlist = new CardList(cardsContainer, cardElements);
  84.   cardlist.render();
  85.  
  86.   document.querySelector('.button.user-info__edit').addEventListener('click', () => {
  87.       editProfilePopup.open();
  88.       formEditValidator.resetErrorrs();
  89.   });
  90.  
  91.   document.querySelector('.button.user-info__button').addEventListener('click', () => {
  92.       newCardPopup.open();
  93.       formNewCardValidator.resetErrorrs();
  94.   });
  95.  
  96.   newCardPopup.popup.addEventListener('submit', e => {
  97.       e.preventDefault();
  98.  
  99.       const card = createCard(newCardPopup.userCardName.value, newCardPopup.userCardURL.value);
  100.       cardlist.addCard(card);
  101.  
  102.       newCardPopup.close();
  103.   });
  104.  
  105.   function createCard(name, link) {
  106.       const card = new Card(name, link);
  107.       const cardElement = card.create();
  108.       card.setEventListeners();
  109.  
  110.       card.image.addEventListener('click', () => {
  111.           imagePopup.open(card.imageUrl);
  112.       });
  113.  
  114.       return cardElement;
  115.   }
  116. })();
  117.  
  118. /* REVIEW:
  119.  
  120. Большинство ошибок были исправлены, отличная работа! Остлось внести небольшие доработки и работа будет принята.
  121. Надо исправить:
  122.  
  123. - При удалении карточки необходимо также удалять обработчики событий с её элементов
  124. - Метод render необходимо вызывать не в в конструкторе класса CardList, а после создания экземпляра класса в index.js
  125. (для загрузки начальных карточек на страницу использовать метод render экземпляра класса CardList)
  126. - Вторым параметром cardList должен принимать массив с начальными карточками, а не пустой массив cardElements
  127.  
  128. В остальном, отличная работа. Желаю Вам хорошего дня!
  129. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement