-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
index.js
189 lines (140 loc) · 5.11 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
const RESPONSIVE_WIDTH = 1024
gsap.registerPlugin(ScrollTrigger)
let headerWhiteBg = false
let isHeaderCollapsed = window.innerWidth < 1024
const collapseHeaderItems = document.getElementById("collapsed-items")
const collapseBtn = document.getElementById("collapse-btn")
const expandingBg = document.getElementById("expanding-header-bg")
gsap.to(expandingBg, {
height: "100%",
duration: 3,
scrollTrigger: {
trigger: "#hero-section",
// pin: true,
start: "50px 10px", // when the top of the trigger hits the top of the viewport
end: "80px 50px",
scrub: 1,
// markers: true
}
})
ScrollTrigger.create({
trigger: "#hero-section",
start: "50px 10px", // when the top of the trigger hits the top of the viewport
end: "60px 40px",
scrub: 1,
// markers: true,
onEnter: () => {
const headerLinks = document.querySelectorAll(".header-links")
// if (window.innerWidth > RESPONSIVE_WIDTH) {
headerLinks.forEach(e => {
e.classList.toggle("header-white-bg")
})
// }
if (isHeaderCollapsed){
collapseBtn.classList.add("primary-text-color")
}
headerWhiteBg = true
},
onEnterBack: () => {
const headerLinks = document.querySelectorAll(".header-links")
// if (window.innerWidth > RESPONSIVE_WIDTH) {
headerLinks.forEach(e => {
e.classList.toggle("header-white-bg")
})
// }
collapseBtn.classList.remove("primary-text-color")
headerWhiteBg = false
}
})
const menuItemContainer = document.querySelectorAll(".menu-item-container")
menuItemContainer.forEach(e => {
const img = e.querySelector("img")
e.addEventListener("mouseenter", () => {
img.style.scale = 1.1
})
e.addEventListener("mouseleave", () => {
img.style.scale = 1
})
})
const reviewContainer = document.querySelector(".review-container")
const reviewSlideShow = new SlideShow(reviewContainer, true, 10000)
function onHeaderClickOutside(e) {
if (!collapseHeaderItems.contains(e.target)) {
toggleHeader()
}
}
function toggleHeader() {
if (isHeaderCollapsed) {
// collapseHeaderItems.classList.remove("max-md:tw-opacity-0")
collapseHeaderItems.classList.add("!tw-opacity-100",)
collapseHeaderItems.style.width = "60vw"
collapseBtn.classList.remove("bi-list", "primary-text-color")
collapseBtn.classList.add("bi-x")
isHeaderCollapsed = false
setTimeout(() => window.addEventListener("click", onHeaderClickOutside), 1)
} else {
collapseHeaderItems.classList.remove("!tw-opacity-100")
collapseHeaderItems.style.width = "0vw"
collapseBtn.classList.remove("bi-x")
collapseBtn.classList.add("bi-list", headerWhiteBg ? "primary-text-color" : null)
isHeaderCollapsed = true
window.removeEventListener("click", onHeaderClickOutside)
}
}
function responsive() {
if (window.innerWidth > RESPONSIVE_WIDTH) {
collapseHeaderItems.style.width = ""
}else{
isHeaderCollapsed = true
collapseBtn.classList.add("bi-list", headerWhiteBg ? "primary-text-color" : null)
}
}
// function
window.addEventListener("resize", responsive)
const bookingDate = document.querySelector("#date")
const today = new Date().toISOString().split('T')[0]
bookingDate.setAttribute('min', today)
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 reviewModal = new Modal(document.querySelector("#modal"))
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){
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)