-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
192 lines (127 loc) · 5 KB
/
script.js
File metadata and controls
192 lines (127 loc) · 5 KB
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
// Button for respnsiveness
const hamburger = document.querySelector('.hamburger');
const navLinks = document.querySelector('.nav-links');
hamburger.addEventListener('click', () => {
navLinks.classList.toggle('active');
});
window.addEventListener('scroll', function () {
const nav = document.querySelector('nav');
if (window.scrollY > 50) {
nav.classList.add('scrolled');
} else {
nav.classList.remove('scrolled');
}
});
// Slide for testimonial
let slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
const slides = document.getElementsByClassName("testimonial-slide");
const dots = document.getElementsByClassName("dot");
if (n > slides.length) { slideIndex = 1 }
if (n < 1) { slideIndex = slides.length }
// Hide all slides
for (let i = 0; i < slides.length; i++) {
slides[i].classList.remove("active");
}
// Deactivate all dots
for (let i = 0; i < dots.length; i++) {
dots[i].classList.remove("active");
}
// Show current slide and activate dot
slides[slideIndex - 1].classList.add("active");
dots[slideIndex - 1].classList.add("active");
}
// Initialize event listeners
document.addEventListener('DOMContentLoaded', function() {
// Button controls
document.querySelector('.prev').addEventListener('click', () => plusSlides(-1));
document.querySelector('.next').addEventListener('click', () => plusSlides(1));
// Dot controls
const dots = document.querySelectorAll('.dot');
dots.forEach((dot, index) => {
dot.addEventListener('click', () => currentSlide(index + 1));
});
});
// Alert interactivity for whole page
// Main alert controller function
function setupAllAlerts() {
// Alert for icons (user and cart)
const alertIcons = document.querySelectorAll('.alert');
alertIcons.forEach(icon => {
icon.addEventListener('click', (e) => {
e.preventDefault();
if (icon.classList.contains('fa-user')) {
showCustomAlert('Server is down😴');
} else if (icon.classList.contains('fa-shopping-cart')) {
showCustomAlert('This feature is currently under maintenance. Please check back later!😥');
}
});
});
// Alert for shop button
document.querySelector('.shop.btn-primary')?.addEventListener('click', (e) => {
e.preventDefault();
showCustomAlert('Our shop is getting a quick makeover! 🛠️ Please check back soon.');
});
// Alert for explore button
document.querySelector('.explore.btn-secondary')?.addEventListener('click', (e) => {
e.preventDefault();
showCustomAlert('Our exploration features are coming soon! Stay tuned for exciting updates.');
});
// Alert for learn button
document.querySelector('.Learn')?.addEventListener('click', (e) => {
e.preventDefault();
// Alert for learn button
document.querySelector('.Learn')?.addEventListener('click', (e) => {
showCustomAlert('Our learning resources are coming soon! Stay tuned for educational content.');
});
// Alert for feature cards
document.querySelectorAll('.feature-card').forEach(card => {
card.addEventListener('click', (e) => {
e.preventDefault();
showCustomAlert("❌ Unavailable\nThis service is not available today.🙁");
});
});
// Alert for add-to-cart buttons
document.querySelectorAll('.add-to-cart').forEach(button => {
button.addEventListener('click', (e) => {
e.preventDefault();
showCustomAlert("❌ Unavailable\n This is out of stoke.😥");
});
});
// Alert for service boxes
document.querySelectorAll('.service-box').forEach(box => {
box.addEventListener('click', () => {
showCustomAlert("No");
});
});
// New alert for room-box
document.querySelectorAll('.room-box').forEach(box => {
box.addEventListener('click', (e) => {
e.preventDefault();
showCustomAlert("This room set is currently unavailable for purchase. Please check back later!");
});
});
}
// Universal alert function with event listener cleanup
function showCustomAlert(message) {
const alertBox = document.getElementById('customAlert');
const alertMessage = document.getElementById('alertMessage');
const okBtn = document.getElementById('alertOkBtn');
// Clone button to prevent duplicate event listeners
const newOkBtn = okBtn.cloneNode(true);
okBtn.parentNode.replaceChild(newOkBtn, okBtn);
alertMessage.textContent = message;
alertBox.style.display = 'flex';
newOkBtn.addEventListener('click', () => {
alertBox.style.display = 'none';
});
}
// Initialize all alerts when DOM is loaded
document.addEventListener('DOMContentLoaded', setupAllAlerts);