Skip to content

Commit

Permalink
Merge pull request #16 from PavelUd/master
Browse files Browse the repository at this point in the history
  • Loading branch information
keksobot authored Dec 22, 2023
2 parents 7322bbf + 0f5aa61 commit afd20c4
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 46 deletions.
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ <h2 class="success__title">Изображение успешно загруже
<template id="messages">
<div class="img-upload__message img-upload__message--loading">Загружаем...</div>
</template>
<script type="text/javascript" src="js/functions.js"></script>
<script src="nouislider/nouislider.js"></script>
<script src="pristine/Pristine-master/dist/pristine.min.js"></script>
<script type="module" src="js/main.js"></script>
Expand Down
7 changes: 5 additions & 2 deletions js/filters.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {thumbnailsRender, destroyThumbnails} from './thumbnails.js';
import{shuffle, sortByCommentCountDescending, debounce} from './util.js';
import { renderBigPicture } from './fullsize-images-render.js';

const HIDDEN_CLASS = 'img-filters--inactive';
const ACTIVE_FILTER_CLASS = 'img-filters__button--active';
Expand Down Expand Up @@ -30,15 +31,17 @@ const onFiltersFormClick = (evt) =>{
filtersForm.querySelector(`#${activeFilter}`).classList.remove(ACTIVE_FILTER_CLASS);
evt.target.classList.add(ACTIVE_FILTER_CLASS);
activeFilter = id;
const pictures = filterFinction[id]();
destroyThumbnails();
thumbnailsRender(filterFinction[id]());
thumbnailsRender(pictures);
renderBigPicture(pictures);
}
};

export const initFilters = (data) =>{
photos = data.slice();
filtersContainer.classList.remove(HIDDEN_CLASS);
filtersForm.addEventListener('click', debounce(onFiltersFormClick));

thumbnailsRender(photos);
renderBigPicture(photos);
};
17 changes: 12 additions & 5 deletions js/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,18 @@ const onFocusPreventClose = (evt) => {
}
};

const onComentsKeydown = (evt) => () => onFocusPreventClose(evt);
const onHashtagsKeydown = (evt) => () => onFocusPreventClose(evt);
const onComentsKeydown = (evt) => onFocusPreventClose(evt);
const onHashtagsKeydown = (evt) => onFocusPreventClose(evt);

const onEscapeKeydown = (evt) => {
if(isEscapeKey(evt)){
form.reset();
closeOverlay();
}
};

const onCancelButtonClick = () => {
form.reset();
closeOverlay();
};

Expand All @@ -87,17 +89,22 @@ const validateForm = () => {
return pristine.validate();
};


const onFormSubmit = (evt) => {
evt.preventDefault();
if (validateForm()) {
blockSubmitButton();
sendData(new FormData(evt.target))
.then(() =>{
closeOverlay();
showSuccessMessage();
form.reset();
})
.catch(showErrorMessage)
.finally(unblockSubmitButton);
.finally(() => {
unblockSubmitButton();
closeOverlay();
}
);
}
};

Expand All @@ -110,7 +117,6 @@ function closeOverlay () {
document.removeEventListener('keydown', onEscapeKeydown);
destroyScaleButtons();
resetFilters();
form.reset();
}

const uploadFile = () => {
Expand All @@ -135,6 +141,7 @@ const onUploadButtonChange = () => {
};

export const renderUploadForm = () => {

uploadButton.addEventListener('change', onUploadButtonChange);
createEffectSlider();
};
Expand Down
5 changes: 4 additions & 1 deletion js/fullsize-images-render.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isEscapeKey } from './util.js';

const LIMIT = 5;
const bigPicture = document.querySelector('.big-picture');
const commentsCount = bigPicture.querySelector('.comments-count');
Expand Down Expand Up @@ -51,7 +53,7 @@ const createCommentsBlock = () =>{
};

const onDocumentKeydown = (evt) => {
if (evt.key === 'Escape') {
if (isEscapeKey(evt)) {
hideModal();
}
};
Expand Down Expand Up @@ -92,6 +94,7 @@ const showBigPicture = (picture, photoInfo, image) => {
document.addEventListener('keydown', onDocumentKeydown);
};


export const renderBigPicture = (photoInfos) => {
const pictures = document.querySelectorAll('.picture');
photos = photoInfos.slice();
Expand Down
32 changes: 0 additions & 32 deletions js/functions.js

This file was deleted.

5 changes: 1 addition & 4 deletions js/image-effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ const Effect = {
options: {range: {min: 1, max: 4}, step: 0.1, start: 4},
}
};
const DefaultSliderParam = {
range: {min: 0, max: 100}, start: 100, step: 0.1
};

const DEFAULT_FILTER = 'NONE';
const image = document.querySelector('.img-upload__preview').querySelector('img');
Expand All @@ -31,7 +28,7 @@ const slider = document.querySelector('.effect-level__slider');

export const createEffectSlider = () =>{
sliderWrapper.classList.add('hidden');
noUiSlider.create(slider, DefaultSliderParam);
noUiSlider.create(slider, Effect[DEFAULT_FILTER].options);
};

export const resetFilters = () => {
Expand Down
2 changes: 1 addition & 1 deletion js/util.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const TIMEOUT_DELAY = 250;
const TIMEOUT_DELAY = 500;
const ALERT_SHOW_TIME = 5000;

const shuffle = (arr) => arr.map((element) => [Math.random(), element])
Expand Down

0 comments on commit afd20c4

Please sign in to comment.