-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathhomestays.js
296 lines (247 loc) · 12.7 KB
/
homestays.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
document.addEventListener("DOMContentLoaded", () => {
/* ============================ FILTER FUNCTIONALITY ============================ */
const locationFilter = document.getElementById("locationFilter");
const priceFilter = document.getElementById("priceFilter");
const currentPriceDisplay = document.getElementById("currentPrice");
const bedroomFilter = document.getElementById("bedroomFilter");
const ratingFilter = document.getElementById("ratingFilter");
const availabilityFilter = document.getElementById("availabilityFilter");
const sortByFilter = document.getElementById("sortBy");
const applyFiltersButton = document.getElementById("applyFilters");
const homestayCards = document.querySelectorAll(".homestay-card");
priceFilter.addEventListener("input", () => {
currentPriceDisplay.textContent = `₹${priceFilter.value}`;
});
applyFiltersButton.addEventListener("click", () => {
const selectedLocation = locationFilter.value.toLowerCase();
const selectedPrice = parseInt(priceFilter.value, 10);
const selectedBedrooms = bedroomFilter.value;
const selectedRating = parseFloat(ratingFilter.value) || 0;
const selectedAvailability = availabilityFilter.value.toLowerCase();
const sortBy = sortByFilter.value;
const filteredCards = Array.from(homestayCards).filter((card) => {
const cardLocation = card.getAttribute("data-location").toLowerCase();
const cardPrice = parseInt(card.getAttribute("data-price"), 10);
const cardBedrooms = card.getAttribute("data-bedrooms");
const cardRating = parseFloat(card.getAttribute("data-rating"));
const cardAvailability = card.getAttribute("data-status").toLowerCase();
let isVisible = true;
if (selectedLocation !== "all" && cardLocation !== selectedLocation) isVisible = false;
if (cardPrice > selectedPrice) isVisible = false;
if (selectedBedrooms !== "all" && cardBedrooms !== selectedBedrooms) isVisible = false;
if (selectedRating > 0 && cardRating < selectedRating) isVisible = false;
if (selectedAvailability !== "all" && cardAvailability !== selectedAvailability) isVisible = false;
return isVisible;
});
homestayCards.forEach((card) => {
card.style.display = filteredCards.includes(card) ? "" : "none";
});
sortCards(sortBy, filteredCards);
});
function sortCards(sortBy, cardsToSort) {
const cardContainer = document.querySelector(".card-container");
if (sortBy === "priceLowHigh") {
cardsToSort.sort((a, b) => a.getAttribute("data-price") - b.getAttribute("data-price"));
} else if (sortBy === "priceHighLow") {
cardsToSort.sort((a, b) => b.getAttribute("data-price") - a.getAttribute("data-price"));
} else if (sortBy === "ratingsHighLow") {
cardsToSort.sort((a, b) => b.getAttribute("data-rating") - a.getAttribute("data-rating"));
}
cardsToSort.forEach((card) => cardContainer.appendChild(card));
}
/* ============================ PRICE CALCULATOR ============================ */
const checkInDate = document.getElementById("checkInDate");
const checkOutDate = document.getElementById("checkOutDate");
const guestCount = document.getElementById("guestCount");
const roomType = document.getElementById("roomType");
const priceDisplay = document.getElementById("priceDisplay");
const calculatePriceBtn = document.getElementById("calculatePriceBtn");
calculatePriceBtn.addEventListener("click", () => {
const checkIn = new Date(checkInDate.value);
const checkOut = new Date(checkOutDate.value);
const guests = parseInt(guestCount.value, 10) || 0;
const room = roomType.value;
if (!checkIn || !checkOut || !room) {
alert("Please fill in all required fields to calculate the price.");
return;
}
const days = (checkOut - checkIn) / (1000 * 60 * 60 * 24);
if (days <= 0) {
alert("Check-Out date must be later than Check-In date.");
return;
}
const roomPrices = {
single: 2000,
double: 3000,
suite: 5000,
villa: 8000,
};
const basePrice = roomPrices[room] || 0;
const totalPrice = basePrice * days + guests * 500;
priceDisplay.textContent = `₹${totalPrice}`;
});
/* ============================ GOOGLE MAP RENDERING ============================ */
const mapLocationFilter = document.getElementById("mapLocationFilter");
const mapPriceFilter = document.getElementById("mapPriceFilter");
const mapFilterApply = document.getElementById("mapFilterApply");
const map = new google.maps.Map(document.getElementById("mapContainer"), {
center: { lat: 20.5937, lng: 78.9629 },
zoom: 5,
});
const locations = [
{ name: "Traditional Haveli in Rajasthan", lat: 27.0238, lng: 74.2176, price: 2500, location: "Rajasthan" },
{ name: "Cozy Cottage in Kerala", lat: 10.8505, lng: 76.2711, price: 1800, location: "Kerala" },
{ name: "Mountain Retreat in Himachal", lat: 31.1048, lng: 77.1734, price: 2200, location: "Himachal Pradesh" },
{ name: "Spacious Villa in Uttarakhand", lat: 30.0668, lng: 79.0193, price: 3000, location: "Uttarakhand" },
{ name: "Heritage Home in Tamil Nadu", lat: 11.1271, lng: 78.6569, price: 2800, location: "Tamil Nadu" },
{ name: "Charming Cottage in Madhya Pradesh", lat: 22.9734, lng: 78.6569, price: 1500, location: "Madhya Pradesh" },
];
const markers = [];
const renderMarkers = (filteredLocations) => {
markers.forEach((marker) => marker.setMap(null));
markers.length = 0;
filteredLocations.forEach((loc) => {
const marker = new google.maps.Marker({
position: { lat: loc.lat, lng: loc.lng },
map: map,
title: loc.name,
});
const infoWindow = new google.maps.InfoWindow({
content: `<h3>${loc.name}</h3><p>Price: ₹${loc.price}/Day</p>`,
});
marker.addListener("click", () => infoWindow.open(map, marker));
markers.push(marker);
});
};
renderMarkers(locations);
mapFilterApply.addEventListener("click", () => {
const selectedLocation = mapLocationFilter.value;
const selectedPrice = mapPriceFilter.value;
const filteredLocations = locations.filter((loc) => {
const matchesLocation = selectedLocation === "all" || loc.location === selectedLocation;
const matchesPrice = selectedPrice === "all" || loc.price <= parseInt(selectedPrice, 10);
return matchesLocation && matchesPrice;
});
renderMarkers(filteredLocations);
});
/* ============================ BOOKING CONFIRMATION MODAL ============================ */
const bookingForm = document.getElementById('bookingForm');
const bookingConfirmationModal = document.getElementById('bookingConfirmationModal');
const closeConfirmationModal = document.getElementById('closeConfirmationModal');
const confirmBookingBtn = document.getElementById('confirmBookingBtn');
const confirmationMessage = document.getElementById('confirmationMessage');
const rebookingPrompt = document.getElementById('rebookingPrompt');
const bookingReferenceNumber = document.getElementById('bookingReferenceNumber');
bookingForm.addEventListener('submit', (event) => {
event.preventDefault();
const checkInDate = document.getElementById('checkInDate').value;
const checkOutDate = document.getElementById('checkOutDate').value;
const guestCount = document.getElementById('guestCount').value;
const roomType = document.getElementById('roomType').value;
const specialRequests = document.getElementById('specialRequests').value;
const totalCost = document.getElementById('priceDisplay').textContent;
const selectedLocation = document.getElementById('selectedLocation').value;
document.getElementById('confirmselectedLocation').textContent = selectedLocation;
document.getElementById('confirmCheckInDate').textContent = checkInDate;
document.getElementById('confirmCheckOutDate').textContent = checkOutDate;
document.getElementById('confirmGuestCount').textContent = guestCount;
document.getElementById('confirmRoomType').textContent = roomType;
document.getElementById('confirmSpecialRequests').textContent = specialRequests;
document.getElementById('confirmTotalCost').textContent = totalCost;
bookingConfirmationModal.style.display = 'flex';
});
closeConfirmationModal.addEventListener('click', () => {
bookingConfirmationModal.style.display = 'none';
});
confirmBookingBtn.addEventListener('click', () => {
const referenceNumber = Math.floor(Math.random() * 1000000);
bookingReferenceNumber.textContent = referenceNumber;
confirmationMessage.style.display = 'block';
setTimeout(() => {
confirmationMessage.style.display = 'none';
rebookingPrompt.style.display = 'block';
}, 4000);
});
document.getElementById('yesRebookBtn').addEventListener('click', () => {
bookingConfirmationModal.style.display = 'none';
bookingForm.reset();
});
document.getElementById('noRebookBtn').addEventListener('click', () => {
rebookingPrompt.style.display = 'none';
});
/* ============================ BACK TO TOP BUTTON ============================ */
const backToTopBtn = document.getElementById("backToTop");
window.addEventListener("scroll", () => {
if (window.scrollY > 300) {
backToTopBtn.classList.add("show");
} else {
backToTopBtn.classList.remove("show");
}
});
backToTopBtn.addEventListener("click", () => {
window.scrollTo({ top: 0, behavior: "smooth" });
});
/* ============================ CHAT BUTTON ============================ */
const chatButton = document.getElementById("chatButton");
chatButton.addEventListener("click", () => {
alert("Chat feature is under construction. Coming soon!");
});
/* ============================ WISHLIST TOGGLE ============================ */
document.querySelectorAll(".add-to-wishlist-btn").forEach((button) => {
button.addEventListener("click", () => {
button.classList.toggle("active");
const icon = button.querySelector("i");
icon.classList.toggle("far");
icon.classList.toggle("fas");
});
});
});
/* ============================ TESTIMONIAL CAROUSAL SECTION ============================ */
const testimonials = [
{
text: "This was one of the most comfortable stays I've ever had. Highly recommend this homestay!",
name: "Sohini Sinha",
rating: "⭐⭐⭐⭐⭐"
},
{
text: "An unforgettable experience! The hospitality was exceptional and the location perfect.",
name: "Shreyoshi Chatterjee",
rating: "⭐⭐⭐⭐⭐"
},
{
text: "A home away from home. The amenities were top-notch and the staff was incredibly friendly.",
name: "Ananya Mondal",
rating: "⭐⭐⭐⭐⭐"
},
{
text: "I loved every moment of my stay. The views were breathtaking and the service was impeccable.",
name: "Snigdha Layek",
rating: "⭐⭐⭐⭐⭐"
}
];
let currentIndex = 0;
function displayTestimonials() {
const testimonialElements = document.querySelectorAll('.testimonial');
testimonialElements.forEach((element, index) => {
element.style.transform = `translateX(${(index - currentIndex) * 100}%)`;
});
}
document.querySelector('.next-btn').addEventListener('click', () => {
currentIndex = (currentIndex + 1) % testimonials.length;
displayTestimonials();
});
document.querySelector('.prev-btn').addEventListener('click', () => {
currentIndex = (currentIndex - 1 + testimonials.length) % testimonials.length;
displayTestimonials();
});
document.querySelector('.write-review-btn').addEventListener('click', () => {
const reviewText = prompt("Please enter your review:");
const reviewerName = prompt("Please enter your name:");
const newTestimonial = {
text: reviewText,
name: reviewerName,
rating: "⭐⭐⭐⭐⭐"
};
testimonials.push(newTestimonial);
displayTestimonials();
});