Skip to content

Commit d971f2a

Browse files
author
Keks
committed
✔️ Сборка #10
1 parent 41bb105 commit d971f2a

File tree

3 files changed

+26
-23
lines changed

3 files changed

+26
-23
lines changed

10/js/form-validation.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,46 @@ const pristine = new Pristine(formElement, {
1414

1515
const hashtag = /^#[a-zа-яё0-9]{1,19}$/i;
1616

17-
const isHashtagValid = (value) => hashtag.test(value);
17+
const convertHashtags = (value) => value.trim().toLowerCase().split(/\s+/);
1818

19-
const isEveryHashtagValid = (hashtags) => hashtags.every((item) => isHashtagValid(item));
19+
const checkHashtagValid = (value) => hashtag.test(value);
2020

21-
const isHashtagsCountValid = (hashtags) => hashtags.length <= MAX_HASHTAGS_COUNT;
21+
const checkEveryHashtagValid = (hashtags) => hashtags.every((item) => checkHashtagValid(item));
2222

23-
const isHashtagsUnique = (hashtags) => new Set(hashtags).size === hashtags.length;
23+
const checkHashtagsCountValid = (hashtags) => hashtags.length <= MAX_HASHTAGS_COUNT;
24+
25+
const checkHashtagsUnique = (hashtags) => new Set(hashtags).size === hashtags.length;
26+
27+
let isEveryHashtagValid = true;
28+
let isHashtagsCountValid = true;
29+
let isHashtagsUnique = true;
2430

2531
const validateHashtagsField = (value) => {
26-
if (!value) {
32+
if (!value.trim()) {
2733
return true;
2834
}
2935

30-
const hashtags = value.trim().split(/\s+/);
36+
const hashtags = convertHashtags(value);
3137

32-
return isEveryHashtagValid(hashtags) && isHashtagsCountValid(hashtags) && isHashtagsUnique(hashtags);
38+
isEveryHashtagValid = checkEveryHashtagValid(hashtags);
39+
isHashtagsCountValid = checkHashtagsCountValid(hashtags);
40+
isHashtagsUnique = checkHashtagsUnique(hashtags);
41+
42+
return isEveryHashtagValid && isHashtagsCountValid && isHashtagsUnique;
3343
};
3444

3545
const validateDescriptionField = (value) => value.length <= MAX_DESCRIPTION_LENGTH;
3646

37-
const getHashtagsErrorMessage = (value) => {
38-
const hashtags = value.trim().split(/\s+/);
39-
40-
if (!isEveryHashtagValid(hashtags)) {
47+
const getHashtagsErrorMessage = () => {
48+
if (!isEveryHashtagValid) {
4149
return 'Невалидный хэштег';
4250
}
4351

44-
if (!isHashtagsUnique(hashtags)) {
52+
if (!isHashtagsUnique) {
4553
return 'Хэштеги повторяются';
4654
}
4755

48-
if (!isHashtagsCountValid(hashtags)) {
56+
if (!isHashtagsCountValid) {
4957
return 'Не более 5 хэштегов';
5058
}
5159
};

10/js/form.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const sliderWrapperElement = modalFormElement.querySelector('.img-upload__effect
1313

1414
const onDocumentKeydown = (evt) => {
1515
if (isEscKey(evt)) {
16-
if (evt.target.matches('.text__description')) {
16+
if (evt.target.matches('.text__description') || evt.target.matches('.text__hashtags')) {
1717
evt.stopPropagation();
1818
} else {
1919
evt.preventDefault();

10/js/photo-filters.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const EffectsNames = {
1+
const EffectsMap = {
22
'chrome': 'grayscale',
33
'sepia': 'sepia',
44
'marvin': 'invert',
@@ -81,24 +81,19 @@ const onSliderUpdate = () => {
8181
const sliderValue = sliderElement.noUiSlider.get();
8282
effectFieldElement.value = `${sliderValue}`;
8383

84-
if (currentFilter) {
85-
const style = `${EffectsNames[currentFilter]}(${sliderValue}${currentFilter === 'marvin' ? '%' : ''}${currentFilter === 'phobos' ? 'px' : ''})`;
84+
const propertyValue = `${EffectsMap[currentFilter]}(${sliderValue}${currentFilter === 'marvin' ? '%' : ''}${currentFilter === 'phobos' ? 'px' : ''})`;
8685

87-
imageElement.style.filter = `${style}`;
88-
}
86+
imageElement.style.filter = `${propertyValue}`;
8987
};
9088

9189
const onEffectsListChange = (evt) => {
9290
if (evt.target.matches('.effects__radio')) {
93-
9491
const targetElementValue = evt.target.value;
9592

9693
if (targetElementValue === 'none') {
9794
sliderWrapperElement.classList.add('hidden');
9895
currentFilter = '';
99-
imageElement.style = '';
100-
sliderElement.noUiSlider.set(100);
101-
96+
imageElement.style.filter = 'none';
10297
} else {
10398
sliderWrapperElement.classList.remove('hidden');
10499
currentFilter = targetElementValue;

0 commit comments

Comments
 (0)