forked from Suchitra-Sahoo/AgriLearnNetwork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
308 lines (259 loc) · 8.9 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
let menuIcon = document.querySelectorAll('#menu-icon');
let navbar = document.querySelectorAll('.navbar');
let Contact = document.querySelectorAll('#contact');
let navContact = document.querySelectorAll('#nav--contact');
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
});
});
});
// 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');
}
let header=document.querySelectorAll('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,
backSpped: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';
}
});