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

Отрисуй меня полностью #6

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 @@ -129,7 +129,6 @@ <h2 class="img-upload__title visually-hidden">Загрузка фотограф
</div>
</form>
</div>
</section>

<!-- Здесь будут изображения других пользователей -->

Expand Down Expand Up @@ -234,6 +233,7 @@ <h2 class="success__title">Изображение успешно загруже
<script type="text/javascript" src="js/functions.js"></script>
<script type="module" src="js/util.js"></script>
<script type="module" src="js/main.js"></script>
<script type="module" src="js/thumbnails-renderer.js"></script>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

название подсокартить

<script type="module" src="js/data.js"></script>
</body>
</html>
5 changes: 2 additions & 3 deletions js/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const MESSAGES = ['', 'Всё отлично!В целом всё неплохо
'Я поскользнулся на банановой кожуре и уронил фотоаппарат на кота и у меня получилась фотография лучше.',
'Лица у людей на фотке перекошены, как будто их избивают. Как можно было поймать такой неудачный момент?!'];
const NAMES= ['Aboba', 'MegaGrib', 'Nagibator3000', 'Artem', 'Ghg', 'top_php_progger'];
const PHOTOS_COUNT = 25;
const MAX_COMMENTS_COUNT = 30;
const LikesCount = {
MIN: 15,
Expand All @@ -23,8 +22,8 @@ const getComments = (quantity, id) => new Array(quantity).fill('').map((_, messa
};
});

export const getPhotoDescriptions = () =>
new Array(PHOTOS_COUNT).fill('').map((_, id) => ({
export const getPhotoDescriptions = (photosCount) =>
new Array(photosCount).fill('').map((_, id) => ({
id: id,
url :`photos/${id}.jpg`,
description : 'Мое придуманное описание',
Expand Down
5 changes: 4 additions & 1 deletion js/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import {getPhotoDescriptions} from './data.js';
import {thumbnailsRender} from './thumbnails-renderer.js';

getPhotoDescriptions();
const PHOTOS_COUNT = 26;
const photos = getPhotoDescriptions(PHOTOS_COUNT);
thumbnailsRender(photos);
26 changes: 26 additions & 0 deletions js/thumbnails-renderer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
let photos = null;

const NULL_INDEX = 0;
const templatePicture = document.querySelector('#picture').content;
const pictures = document.querySelector('.pictures');

const getPicture = (photo) =>{
const picture = templatePicture.cloneNode(true);
const img = picture.querySelector('.picture__img');
img.src = photo.url;
img.alt = photo.description;
picture.querySelector('.picture__likes').textContent = photo.likes;
picture.querySelector('.picture__comments').textContent = photo.comments.length;
return picture;
};

export const thumbnailsRender = (data) =>{
photos = data.slice();
if(photos){
photos.forEach((photo, index) => {
if(index > NULL_INDEX){
pictures.appendChild(getPicture(photo));
}
});
}
};
Loading