diff --git a/src/css/rating-popup.css b/src/css/rating-popup.css index f5585f4..65599cd 100644 --- a/src/css/rating-popup.css +++ b/src/css/rating-popup.css @@ -62,6 +62,16 @@ fill: var(--rating-color); } +.modal-rating__rating polygon:hover { + cursor: pointer; + fill: var(--accent-color); + transition: all var(--tran-icon); +} + +.modal-rating__rating polygon.active { + fill: var(--accent-color); +} + .modal-rating__form { display: flex; flex-direction: column; diff --git a/src/js/exercise-popup.js b/src/js/exercise-popup.js index 3dc75bd..38639bd 100644 --- a/src/js/exercise-popup.js +++ b/src/js/exercise-popup.js @@ -214,7 +214,7 @@ function showModalExercise() { function closeModalExercise() { overlay.classList.add('hidden'); modalExercise.classList.add('hidden'); - document.body.style.overflow = 'scroll'; + document.body.style.overflow = 'auto'; overlay.removeEventListener('click', clickOnOverlay); document.removeEventListener('keydown', clickOnEscape); }; \ No newline at end of file diff --git a/src/js/rating-popup.js b/src/js/rating-popup.js index 8932692..5753c07 100644 --- a/src/js/rating-popup.js +++ b/src/js/rating-popup.js @@ -2,6 +2,7 @@ import icons from '/img/icons.svg'; const modalExercise = document.querySelector('.js-modal-exercise'); const modalRating = document.querySelector('.js-modal-rating'); +const starsIcons = document.querySelector('.js-stars-svg'); export function openModalRating() { const buttonRating = document.querySelector('.js-rating__btn'); @@ -9,10 +10,39 @@ export function openModalRating() { modalRating.innerHTML = markUp(); showModalRating(); - const closeModalRatingButton = document.querySelector('.js-modal-rating__btn-close'); + const closeModalRatingButton = document.querySelector('.js-modal-rating__btn-close'); + const starsIcons = document.querySelector('.js-stars-svg'); closeModalRatingButton.addEventListener('click', closeModalRating); + starsIcons.addEventListener('click', changeStarsRating); + // starsIcons.addEventListener('mouseover', handleHoverEvent); + listenPolygons(); }; +function submitRating() { + document.querySelector('.js-rating-form').addEventListener('submit', e => { + e.preventDefault(); + }) +} + +function listenPolygons () { + const polygons = document.querySelectorAll('.js-stars-svg polygon'); + + polygons.forEach(polygon => { + polygon.addEventListener('mouseenter', function() { + const value = parseInt(this.getAttribute('data-value')); + + polygons.forEach((p, index) => { + if (index < value) { + p.classList.add('active'); + document.querySelector('.js-rating-value').textContent = value; + } else { + p.classList.remove('active'); + } + }); + }); + }); +} + function showModalRating() { modalExercise.classList.add('hidden'); modalRating.classList.remove('hidden'); @@ -23,6 +53,18 @@ function closeModalRating() { modalRating.classList.add('hidden'); }; +function changeStarsRating(e) { + const starsIcons = document.querySelector('.js-stars-svg'); + let value = e.target.dataset.value; + value && (starsIcons.parentNode.dataset.value = value); + starsIcons.querySelectorAll('polygon').forEach(star => { + let on = starsIcons.parentNode.dataset.value >= star.dataset.value; + star.classList.toggle('active', on); + }); + document.querySelector('.js-rating-value').textContent = value; + submitRating() +}; + function markUp() { return `