forked from Suchitra-Sahoo/AgriLearnNetwork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
432 lines (356 loc) · 13 KB
/
script.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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
let menuIcon = document.querySelectorAll('#menu-icon');
let navbar = document.querySelectorAll('.navbar');
let Contact = document.querySelectorAll('#contact');
let navContact = document.querySelectorAll('#nav--contact');
const password = document.getElementById('password');
menuIcon.forEach(icon => {
icon.onclick = () => {
icon.classList.toggle('bx-x');
navbar.forEach(nav => nav.classList.toggle('active'));
}
});
// Add an event listener to navbar links
document.querySelectorAll('.navbar a').forEach(link => {
link.addEventListener('click', () => {
// Remove 'active' class from navbar
document.querySelectorAll('.navbar').forEach(nav => {
nav.classList.remove('active');
});
// Toggle the menu icon
document.querySelectorAll('#menu-icon').forEach(icon => {
icon.classList.remove('bx-x'); // Remove the 'bx-x' class to close the hamburger menu
});
});
});
//smooth background sliding images transition
document.addEventListener('DOMContentLoaded', () => {
const slideGroup = document.querySelector('.slide_group');
const slides = document.querySelectorAll('.slide');
const slideWidth = 100 / slides.length; // Calculate width percentage for each slide
let currentIndex = 0;
const totalSlides = slides.length;
const transitionDuration = 800; // Duration in milliseconds
function goToSlide(index) {
slideGroup.style.transition = `transform ${transitionDuration}ms ease-in-out`;
slideGroup.style.transform = `translateX(-${index * slideWidth}%)`;
currentIndex = index;
}
function nextSlide() {
if (currentIndex < totalSlides - 2) { // Penultimate slide
goToSlide(currentIndex + 1);
} else if (currentIndex === totalSlides - 2) { // Before last slide (duplicate of the first)
goToSlide(currentIndex + 1);
slideGroup.addEventListener('transitionend', resetPosition, { once: true });
}
}
function resetPosition() {
slideGroup.style.transition = 'none';
slideGroup.style.transform = 'translateX(0)'; // Reset to the first slide
currentIndex = 0; // Reset index to the first slide
// Force reflow to make the change immediate
slideGroup.offsetHeight; // Reading offsetHeight reflows the DOM
slideGroup.style.transition = `transform ${transitionDuration}ms ease-in-out`;
}
setInterval(nextSlide, 3000); // Change slide every 3 seconds
});
// Add an "active" class to the clicked link
$('a[href*="#"]')
.not('[href="#"]')
.not('[href="#0"]')
.click(function(event) {
// Remove any existing "active" class from links
$('a').removeClass('active');
// Add "active" class to clicked link
$(this).addClass('active');
// Smooth scroll to target as before
if (
location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '')
&&
location.hostname == this.hostname
) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
if (target.length) {
event.preventDefault();
$('html, body').animate({
scrollTop: target.offset().top
}, 900, function() {
var $target = $(target);
$target.focus();
if ($target.is(":focus")) {
return false;
} else {
$target.attr('tabindex','-1');
$target.focus();
};
});
}
}
});
// When scroll on any section that section's corresponding hyperlink will be active and
// the previous activated hyperlink will be deactivated
$('section[id]').mouseover(function() {
var sectionId = $(this).attr('id');
var correspondingLink = $('a[href="#' + sectionId + '"]');
// Remove active class from all links
$('a').removeClass('active');
// Add active class to the corresponding link
correspondingLink.addClass('active');
});
// Set initial active link based on URL hash
$(document).ready(function() {
var hash = window.location.hash;
if (hash) {
$('a[href="' + hash + '"]').addClass('active');
}
// Change this line from selecting all headers to selecting one header
let header = document.querySelector('header');
header.classList.toggle('sticky', window.scrollY > 100);
});
ScrollReveal({
reset:true,
distance:'80px',
duration:2000,
delay:200
});
ScrollReveal().reveal('.home-content, .heading',{ origin:'top' });
ScrollReveal().reveal('.home-img, .services-container, .portfolio-box, .contact form',{ origin:'bottom' });
ScrollReveal().reveal('.home-content h1, .about-img',{ origin:'left' });
ScrollReveal().reveal('.home-content p, .about-content',{ origin:'left' });
const typed=new Typed('.multiple-text',{
strings:['Sow','Learn','Grow' ],
typeSpeed:100,
backSpeed:100,
backDelay:1000,
loop:true
});
const form = document.getElementById('contact-form');
form.addEventListener('submit', (event) => {
event.preventDefault();
// Access form fields
const fullName = form.querySelector('input[placeholder="Full Name"]').value.trim();
const email = form.querySelector('input[placeholder="Email Address"]').value.trim();
const mobileNumber = form.querySelector('input[placeholder="Mobile Number"]').value.trim();
const emailSubject = form.querySelector('input[placeholder="Email Subject"]').value.trim();
const message = form.querySelector('textarea').value.trim();
// const alertBox = document.getElementById('alertBox');
// alertBox.classList.remove('hidden');
// Validation
const nameRegex = /^[A-Za-z]{2,50}(?: [A-Za-z]{2,50})*$/;
if (!nameRegex.test(fullName)) {
swal({
title: "Custom Styled Alert",
text: "This alert has been styled with custom CSS.",
icon: "info",
button: "Awesome!"
})
swal("Try Again!","Please enter your full name.","warning");
return;
}
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
swal("Try Again!","Please enter a valid email.","warning");
return;
}
const mobileRegex = /^\+?(\d{1,3})?[-.\s]?(\(?\d{3,4}\)?[-.\s]?)?\d{3}[-.\s]?\d{3,4}$/;
if (!mobileRegex.test(mobileNumber)) {
swal("Try Again!","Please enter a valid mobile number.","warning");
return;
}
const emailSubjectRegex = /^[\w\s\p{P}]{10,90}$/;
if (!emailSubjectRegex.test(emailSubject)) {
swal("Try Again!","Please enter email subject.","warning");
return;
}
if (!message) {
swal("Try Again!","Please enter your message.","warning");
return;
}
// form reset
else {
form.reset();
swal("Message received!", "We will get back to you in no time.","success");
}
});
(function(){
let modal = document.getElementById("modal");
let reviewBtn = document.getElementById("review-btn");
let span = document.getElementsByClassName("close")[0];
reviewBtn.onclick = function(e) {
e.preventDefault();
modal.style.display = "flex";
}
span.onclick = function() {
modal.style.display = "none";
}
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
const feedbackForm = document.getElementById("feedback-form");
const submitButton = document.querySelector("#feedback-form button[type='submit']");
// Event listener for form submission
document.addEventListener('DOMContentLoaded', function() {
function allFieldsFilled() {
const inputs = feedbackForm.querySelectorAll("input[type='text'], input[type='email'], textarea");
for (let input of inputs) {
if (!input.value.trim()) {
return false;
}
}
return true;
}
function ratingSelected() {
const stars = document.querySelectorAll('.rating__star');
for (let star of stars) {
if (star.classList.contains('fas')) {
return true;
}
}
return false;
}
const feedbackForm = document.getElementById('feedback-form');
feedbackForm.addEventListener('submit', function(event) {
event.preventDefault();
const thankYouMessage = document.getElementById('thank-you-message');
const errorMessage = document.getElementById('error-message');
if (allFieldsFilled() && ratingSelected()) {
thankYouMessage.style.display = 'block';
errorMessage.style.display = 'none';
setTimeout(function() {
thankYouMessage.style.display = 'none';
},3000);
feedbackForm.reset();
} else {
thankYouMessage.style.display = 'none';
errorMessage.style.display = 'block';
setTimeout(function() {
errorMessage.style.display = 'none';
},3000);
feedbackForm.reset();
}
});
document.querySelector('.close').addEventListener('click', function() {
document.getElementById('modal').style.display = 'none';
});
// Optional: if you want to close the modal when clicking outside of it
window.onclick = function(event) {
if (event.target == document.getElementById('modal')) {
document.getElementById('modal').style.display = 'none';
}
};
});
// Event listener for form input fields
feedbackForm.addEventListener("input", function() {
if (allFieldsFilled()) {
submitButton.removeAttribute("disabled");
} else {
submitButton.setAttribute("disabled", "disabled");
}
});
const ratingStars = [...document.getElementsByClassName("rating__star")];
function executeRating(stars) {
const starClassActive = "rating__star fas fa-star";
const starClassInactive = "rating__star far fa-star";
const starsLength = stars.length;
let i;
stars.map((star) => {
star.onclick = () => {
i = stars.indexOf(star);
if (star.className===starClassInactive) {
for (i; i >= 0; --i) stars[i].className = starClassActive;
} else {
for (i; i < starsLength; ++i) stars[i].className = starClassInactive;
}
};
});
}
executeRating(ratingStars);
})();
document.addEventListener("DOMContentLoaded", function () {
setTimeout(function () {
document.querySelector("body").classList.add("loaded");
}, 500)
});
const loginRegisterBtn = document.getElementById('log-in-btn');
let islogInMode = true;
// Change text on hover
loginRegisterBtn.addEventListener('mouseover', () => {
if (islogInMode) {
loginRegisterBtn.textContent = 'Register';
} else {
loginRegisterBtn.textContent = 'Login In';
}
});
loginRegisterBtn.addEventListener('mouseout', () => {
if (islogInMode) {
loginRegisterBtn.textContent = 'Login';
} else {
loginRegisterBtn.textContent = 'Register';
}
});
// new faq
function toggleAccordion(header) {
const accordion = header.parentNode;
closeAllAccordions(accordion);
accordion.classList.toggle('active');
const body = accordion.querySelector('.accordion-body');
if (body.style.display === 'block') {
body.style.display = 'none';
header.querySelector('img').src = '../faq/Expand-more.svg';
} else {
body.style.display = 'block';
header.querySelector('img').src = '../faq/Expand-less.svg';
}
}
function closeAllAccordions(clickedAccordion) {
const accordions = document.querySelectorAll('.accordion');
accordions.forEach(accordion => {
if (accordion !== clickedAccordion) {
accordion.classList.remove('active');
accordion.querySelector('.accordion-body').style.display = 'none';
accordion.querySelector('.accordion-header img').src = '../faq/Expand-more.svg';
}
});
}
function closeAllAccordions(clickedAccordion) {
const accordions = document.querySelectorAll('.accordion');
accordions.forEach(accordion => {
if (accordion !== clickedAccordion) {
accordion.classList.remove('active');
accordion.querySelector('.accordion-body').style.display = 'none';
accordion.querySelector('.accordion-header img').src = '../faq/Expand-more.svg';
}
});
}
document.addEventListener('DOMContentLoaded', () => {
const faqSection = document.querySelector('../faq .section-heading');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
faqSection.classList.add('visible');
}
});
}, { threshold: 0.1 }); // Trigger when 10% of the element is visible
observer.observe(faqSection);
});
// mode toggle function
document.addEventListener("DOMContentLoaded", function () {
const themeToggle = document.querySelector(".theme-toggle");
const body = document.body;
// Load the saved theme from local storage and apply it
const savedTheme = localStorage.getItem("theme");
if (savedTheme && savedTheme === "dark") {
body.classList.add("dark-theme");
}
themeToggle.addEventListener("click", function () {
body.classList.toggle("dark-theme");
// Save the current theme in local storage
if (body.classList.contains("dark-theme")) {
localStorage.setItem("theme", "dark");
} else {
localStorage.setItem("theme", "light");
}
});
});