-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from Daniil888-m/module11-task1
- Loading branch information
Showing
9 changed files
with
265 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const BASE_URL = 'https://31.javascript.htmlacademy.pro/kekstagram'; | ||
|
||
const Route = { | ||
GET_DATA: '/data', | ||
SEND_DATA: '/' | ||
}; | ||
|
||
const Method = { | ||
GET: 'GET', | ||
POST: 'POST' | ||
}; | ||
|
||
const load = (route, method = Method.GET, body = null) => fetch(`${BASE_URL}${route}`, { body, method }) | ||
.then((response) => { | ||
if (!response.ok) { | ||
throw new Error(); | ||
} | ||
return response.json(); | ||
}).catch(() => { | ||
throw new Error('Ошибка при отправке/получении данных'); | ||
}); | ||
|
||
const getData = () => load(Route.GET_DATA); | ||
|
||
const sendData = (body) => load(Route.SEND_DATA, Method.POST, body); | ||
|
||
export { sendData, getData }; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { Filters, Scale } from './consts'; | ||
import { hide, show } from './utils'; | ||
|
||
const uploadForm = document.querySelector('#upload-select-image'); | ||
const uploadFormPreviewImg = uploadForm.querySelector('.img-upload__preview'); | ||
const scaleControl = uploadForm.querySelector('.scale__control--value'); | ||
const effectsSlider = uploadForm.querySelector('.effect-level__slider'); | ||
const effectsValue = uploadForm.querySelector('.effect-level__value'); | ||
const sliderContainer = uploadForm.querySelector('.img-upload__effect-level'); | ||
|
||
function onSmallerBtnClick(evt) { | ||
evt.preventDefault(); | ||
updateScale(false); | ||
changeImgScale(); | ||
} | ||
function onBiggerBtnClick(evt) { | ||
evt.preventDefault(); | ||
updateScale(true); | ||
changeImgScale(); | ||
} | ||
function updateScale(isIncreasing) { | ||
let scaleValue = parseInt(scaleControl.value, 10); | ||
|
||
scaleValue = isIncreasing | ||
? scaleValue + Scale.SCALE_STEP | ||
: scaleValue - Scale.SCALE_STEP; | ||
|
||
scaleValue = Math.max(Scale.MIN_SCALE, Math.min(Scale.MAX_SCALE, scaleValue)); | ||
|
||
scaleControl.value = `${scaleValue}%`; | ||
} | ||
|
||
function changeImgScale() { | ||
uploadFormPreviewImg.style.transform = `scale(${parseFloat(scaleControl.value) / 100})`; | ||
|
||
} | ||
uploadForm.querySelector('.scale__control--smaller').addEventListener('click', onSmallerBtnClick); | ||
uploadForm.querySelector('.scale__control--bigger').addEventListener('click', onBiggerBtnClick); | ||
|
||
noUiSlider.create(effectsSlider, { | ||
range: { | ||
max: 1, | ||
min: 0, | ||
}, | ||
step: 0.1, | ||
start: 1, | ||
format: { | ||
to: function (value) { | ||
if (!Number.isInteger(value)) { | ||
return value.toFixed(1); | ||
} | ||
return value; | ||
}, | ||
from: function (value) { | ||
return value; | ||
} | ||
} | ||
}); | ||
|
||
function updateEffectsSlider(effect) { | ||
effectsSlider.noUiSlider.updateOptions({ | ||
range: { | ||
max: Filters[effect].MAX_VALUE, | ||
min: Filters[effect].MIN_VALUE, | ||
}, | ||
step: Filters[effect].STEP, | ||
start: Filters[effect].MAX_VALUE, | ||
}); | ||
} | ||
|
||
function hideEffectsContainer() { | ||
hide(sliderContainer); | ||
effectsValue.value = 0; | ||
uploadFormPreviewImg.style.filter = 'none'; | ||
} | ||
|
||
effectsSlider.noUiSlider.on('update', () => { | ||
effectsValue.value = effectsSlider.noUiSlider.get(); | ||
const currentEffect = uploadForm.querySelector('input[name="effect"]:checked').value; | ||
if (!(currentEffect === 'none')) { | ||
uploadFormPreviewImg.style.filter = `${Filters[currentEffect].EFFECT}(${effectsValue.value + Filters[currentEffect].UNIT_OF_MEASUREMENT}`; | ||
} | ||
}); | ||
|
||
uploadForm.querySelector('.img-upload__effects').addEventListener('change', (evt) => { | ||
const currentEffect = evt.target.closest('input[name="effect"]:checked').value; | ||
if (currentEffect) { | ||
if (currentEffect === 'none') { | ||
hideEffectsContainer(); | ||
} else { | ||
show(sliderContainer); | ||
updateEffectsSlider(currentEffect); | ||
uploadFormPreviewImg.style.filter = `${Filters[currentEffect].EFFECT}(${effectsValue.value + Filters[currentEffect].UNIT_OF_MEASUREMENT}`; | ||
} | ||
} | ||
}); | ||
|
||
hideEffectsContainer(); | ||
|
||
export { changeImgScale }; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,24 @@ | ||
import { renderPictures } from './render-pictures.js'; | ||
import { openBigPhotoPopup } from './big-picture-popup.js'; | ||
import './upload-form.js'; | ||
import { getData } from './api.js'; | ||
import { closeUploadOverlay, setUploadFormSubmit } from './upload-form.js'; | ||
import { renderPictures, showDataError } from './render-pictures.js'; | ||
|
||
renderPictures(); | ||
let pictures; | ||
|
||
document.addEventListener('click', (e) => { | ||
const currentPicture = e.target.closest('.picture'); | ||
getData().then((photos) => { | ||
pictures = photos; | ||
renderPictures(pictures); | ||
}) | ||
.catch(showDataError); | ||
|
||
document.addEventListener('click', (evt) => { | ||
const currentPicture = evt.target.closest('.picture'); | ||
|
||
if (currentPicture) { | ||
e.preventDefault(); | ||
openBigPhotoPopup(currentPicture.dataset.photoId); | ||
evt.preventDefault(); | ||
openBigPhotoPopup(pictures, currentPicture.dataset.photoId); | ||
} | ||
|
||
}); | ||
|
||
setUploadFormSubmit(closeUploadOverlay); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.