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

Правда или действие #8

Merged
merged 1 commit into from
Dec 16, 2024
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: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="./vendor/nouislider/nouislider.css">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<title>Кекстаграм</title>
</head>
Expand Down Expand Up @@ -237,5 +238,6 @@ <h2 class="data-error__title">Не удалось загрузить данны
</script>
<script src="./vendor/pristine/pristine.min.js">
</script>
<script src="./vendor/nouislider/nouislider.js"></script>
</body>
</html>
70 changes: 70 additions & 0 deletions js/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
export const EFFECTS = {
NONE: 'none',

Check failure on line 2 in js/constants.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 2 spaces but found 4
CHROME: 'chrome',

Check failure on line 3 in js/constants.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 2 spaces but found 4
SEPIA: 'sepia',

Check failure on line 4 in js/constants.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 2 spaces but found 4
MARVIN: 'marvin',

Check failure on line 5 in js/constants.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 2 spaces but found 4
PHOBOS: 'phobos',

Check failure on line 6 in js/constants.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 2 spaces but found 4
HEAT: 'heat'

Check failure on line 7 in js/constants.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 2 spaces but found 4
};

const EFFECTS_STYLES = {
NONE: '',

Check failure on line 11 in js/constants.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 2 spaces but found 4
GRAYSCALE: 'grayscale',

Check failure on line 12 in js/constants.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 2 spaces but found 4
SEPIA: 'sepia',

Check failure on line 13 in js/constants.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 2 spaces but found 4
INVERT: 'invert',

Check failure on line 14 in js/constants.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 2 spaces but found 4
BLUR: 'blur',
BRIGHTNESS: 'brightness'
}

const UNITS = {
PX: 'px',
NONE: '',
PS: '%'
}

export const EffectsSetting = {
[EFFECTS.NONE]: {
min: 0,
max: 100,
step: 1,
style: EFFECTS_STYLES.NONE,
units: UNITS.NONE
},
[EFFECTS.CHROME]: {
min: 0,
max: 1,
step: 0.1,
style: EFFECTS_STYLES.GRAYSCALE,
units: UNITS.NONE
},
[EFFECTS.SEPIA]: {
min: 0,
max: 1,
step: 0.1,
style: EFFECTS_STYLES.SEPIA,
units: UNITS.NONE
},
[EFFECTS.MARVIN]: {
min: 0,
max: 100,
step: 1,
style: EFFECTS_STYLES.INVERT,
units: UNITS.PS
},
[EFFECTS.PHOBOS]: {
min: 0,
max: 3,
step: 0.1,
style: EFFECTS_STYLES.BLUR,
units: UNITS.PX
},
[EFFECTS.HEAT]: {
min: 1,
max: 3,
step: 0.1,
style: EFFECTS_STYLES.BRIGHTNESS,
units: UNITS.NONE
}
};

export const DEFAULT_EFFECT = EFFECTS.NONE;
59 changes: 59 additions & 0 deletions js/effects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { DEFAULT_EFFECT, EffectsSetting } from "./constants.js";

const effectsList = document.querySelector('.effects__list');
const sliderContainer = document.querySelector('.effect-level__slider');
const value = document.querySelector('.effect-level__value');
const imageUploadPreview = document.querySelector('.img-upload__preview img');
const sliderBlock = document.querySelector('.effect-level');

let currentEffect = DEFAULT_EFFECT;

noUiSlider.create(sliderContainer, {
range: {
min: 0,
max: 100,
},
start: 80,
step: 1,
connect: 'lower',
})

const render = () => {
const { style, units } = EffectsSetting[currentEffect];
imageUploadPreview.style.filter = `${style}(${value.value}${units})`;
}

const updateSlider = () => {
const { min, max, step } = EffectsSetting[currentEffect];
sliderContainer.noUiSlider.updateOptions({
range: {
min,
max,
},
step,
start: max,
}
)
}

sliderContainer.noUiSlider.on('update', () => {
value.value = sliderContainer.noUiSlider.get();
render();
})

export const reset = () => {
imageUploadPreview.style.filter = '';
sliderBlock.classList.add('hidden');
}

effectsList.addEventListener('change', ({ target }) => {
currentEffect = target.value;
if (currentEffect === DEFAULT_EFFECT) {
reset();
} else {
updateSlider();
sliderBlock.classList.remove('hidden');
}
})

reset()
57 changes: 35 additions & 22 deletions js/form.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,47 @@
import { isValid, reset as resetValidation } from "./validation.js";

import { isValid, reset as resetValidation } from './validation.js';
import { reset as resetScale} from './scale.js';
import {reset as resetEffects} from './effects.js';

const uploadForm = document.querySelector('.img-upload__form');
const uploadFileInput = uploadForm.querySelector('.img-upload__input');
const uploadOverlay = uploadForm.querySelector('.img-upload__overlay');
const uploadCancelInput = uploadForm.querySelector('.img-upload__cancel');
const body = document.body;

const openForm = () => {
uploadOverlay.classList.remove('hidden');
body.classList.add('modal-open');
const openForm = () => {
uploadOverlay.classList.remove('hidden');
body.classList.add('modal-open');
}

uploadFileInput.addEventListener('change', () => {
openForm()
openForm()
})

const closeForm = () => {
uploadOverlay.classList.add('hidden');
body.classList.remove('modal-open');
uploadForm.reset();
resetValidation();
resetScale();
resetEffects();
}

uploadCancelInput.addEventListener('click', (evt) => {
evt.preventDefault();
closeForm()
})

const closeForm = () => {
uploadOverlay.classList.add('hidden');
body.classList.remove('modal-open');
}

uploadCancelInput.addEventListener('click', (evt) => {
evt.preventDefault();
closeForm()
})

document.addEventListener('keydown', (evt) => {
if(evt.key === "Escape"){
evt.preventDefault()
closeForm()
}
})
document.addEventListener('keydown', (evt) => {
if (evt.key === "Escape") {
evt.preventDefault()
closeForm()
}
})

const onFormSubmit = (evt) => {
if (!isValid()) {
evt.preventDefault();
}
}

uploadForm.addEventListener('submit', onFormSubmit);
37 changes: 37 additions & 0 deletions js/scale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const SCALE_VALUE_MIN = 25;
const SCALE_VALUE_MAX = 100;
const SCALE_VALUE_STEP = 25;
const SCALE_VALUE_DEFAULT = SCALE_VALUE_MAX;
const FACTOR = 0.01;

const scaleValue = document.querySelector('.scale__control--value');
const imageUploadPreview = document.querySelector('.img-upload__preview img');
const scalleSmaller = document.querySelector('.scale__control--smaller');
const scalleBigger = document.querySelector('.scale__control--bigger');

let currentScale = SCALE_VALUE_DEFAULT;

const render = () => {
scaleValue.value = `${currentScale}%`;
imageUploadPreview.style.transform = `scale(${currentScale * FACTOR})`;
}

const onScalleSmallerClick = () => {
currentScale = currentScale > SCALE_VALUE_MIN ? currentScale - SCALE_VALUE_STEP : SCALE_VALUE_MIN;
render()
}

const onScalleBiggerClick = () => {
currentScale = currentScale < SCALE_VALUE_MAX ? currentScale + SCALE_VALUE_STEP : SCALE_VALUE_MAX;
render()
}

scalleSmaller.addEventListener('click', onScalleSmallerClick);
scalleBigger.addEventListener('click', onScalleBiggerClick);

export const reset = () => {
currentScale = SCALE_VALUE_DEFAULT;
render()
}

reset();
Loading