-
-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathindex.js
129 lines (93 loc) · 3.52 KB
/
index.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
let isHeaderCollapsed = window.innerWidth < 1024
const collapseHeaderItems = document.getElementById("collapsed-items")
const collapseBtn = document.getElementById("collapse-btn")
const heroSlides = document.querySelector(".slideshow-container")
const heroSlideShow = new SlideShow(heroSlides, true, 10000)
const bookingDate = document.querySelector("#date")
const today = new Date().toISOString().split('T')[0]
bookingDate.setAttribute('min', today)
/**
* Set booking timing
*/
const timings = document.querySelector("#timings")
for (let x=7; x < 20; x+=0.30){
const nextTime = `${x.toFixed(2)}`.replace(".", ":")
timings.innerHTML += `<option value="${nextTime}">${nextTime}</option>`
}
const reviewContainer = document.querySelector(".review-container")
const reviewSlideShow = new SlideShow(reviewContainer, true, 10000)
function onHeaderClickOutside(e){
if (!collapseHeaderItems.contains(e.target)){
toggleHeader()
}
}
function toggleHeader(){
// console.log("Colappse", isHeaderCollapsed)
if (isHeaderCollapsed){
// collapseHeaderItems.classList.remove("max-md:tw-opacity-0")
collapseHeaderItems.classList.add("opacity-100")
collapseHeaderItems.style.width = "60vw"
collapseBtn.classList.remove("bi-list")
collapseBtn.classList.add("bi-x")
isHeaderCollapsed = false
setTimeout(() => window.addEventListener("click", onHeaderClickOutside), 1)
}else{
collapseHeaderItems.classList.remove("opacity-100")
collapseHeaderItems.style.width = "0vw"
collapseBtn.classList.remove("bi-x")
collapseBtn.classList.add("bi-list")
isHeaderCollapsed = true
window.removeEventListener("click", onHeaderClickOutside)
}
}
function responsive(){
if (window.innerWidth > 750){
collapseHeaderItems.style.width = ""
}
}
// function
window.addEventListener("resize", responsive)
// review section
const reviewModal = new Modal(document.querySelector("#modal")) // asks for user review
const starContainer = document.querySelector('.stars')
const stars = document.querySelectorAll('.star')
function handleStarHover(event) {
const rating = event.currentTarget.getAttribute('data-value')
stars.forEach(star => {
if (parseInt(star.getAttribute('data-value')) <= rating) {
star.classList.add('active')
} else {
star.classList.remove('active')
}
})
}
function handleStarClicked(event){
/**
* If the rating is above 4 request the user to write a public review, else
* a private review
*/
const rating = event.currentTarget.getAttribute('data-value')
if (rating < 4){
reviewModal.updateModal("We are sorry, you are disappointed",
"Please let us know what we can improve.")
reviewModal.showModalInput()
reviewModal.updateButton("Submit")
}else{
reviewModal.updateModal("Thank you!",
`We are pleased to hear you like us.
Could you please rate us on Google maps?`)
reviewModal.hideModalInput()
reviewModal.updateButton("Open maps", "https://maps.app.goo.gl/")
}
reviewModal.show()
}
function hideActiveStar(){
stars.forEach(star => {
star.classList.remove('active')
})
}
stars.forEach((star, i) => {
star.addEventListener('mouseover', handleStarHover)
star.addEventListener('click', handleStarClicked)
})
starContainer.addEventListener('mouseleave', hideActiveStar)