-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript_reviews.js
54 lines (43 loc) · 1.44 KB
/
script_reviews.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function stickStarRating(){
const reviewSection = document.querySelector('.review')
const starsDiv = reviewSection.querySelectorAll('.stars i')
const starClass = reviewSection.querySelector('.stars')
var score = reviewSection.querySelector('form > input')
// index a começar em 0
starsDiv.forEach(function(star, clickedIndex){
star.addEventListener('click', function(e){
starsDiv.forEach(function(otherStar, otherIndex){
if (clickedIndex >= otherIndex){
otherStar.className = "fas fa-star"
}else{
otherStar.className = "far fa-star"
}
})
if (clickedIndex == 0){
score.value = clickedIndex + 1
}else{
score.value = clickedIndex + 1
}
console.log('star' + star + ' of index ' + clickedIndex)
})
})
}
function reviewScreen(){
const screen = document.querySelector(".popupReview")
const closeBtn = document.querySelector(".review i")
const openBtn = document.querySelector(".review > button")
console.log("openBtn")
console.log("closeBtn")
openBtn.addEventListener("click", function(){
setTimeout(() =>{
screen.classList.add("activeReview")
}, 2)
})
closeBtn.addEventListener("click", function(){
screen.classList.remove("activeReview") // fecha a review
})
}
if (window.location.pathname == "/restaurantPage.php"){
stickStarRating()
reviewScreen()
}