-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
61 lines (58 loc) · 2.12 KB
/
Copy pathapp.js
File metadata and controls
61 lines (58 loc) · 2.12 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
(function () {
[...document.querySelectorAll(".control")].forEach(button => {
button.addEventListener("click", function() {
document.querySelector(".active-btn").classList.remove("active-btn");
this.classList.add("active-btn");
document.querySelector(".active").classList.remove("active");
document.getElementById(button.dataset.id).classList.add("active");
// Scroll to top when switching sections
window.scrollTo({ top: 0, behavior: 'smooth' });
})
});
document.querySelector(".theme-btn").addEventListener("click", () => {
document.body.classList.toggle("light-mode");
})
})();
document.addEventListener("DOMContentLoaded", function () {
document.getElementById("submitButton").addEventListener("click", function (e) {
e.preventDefault();
// Submit the form using AJAX
var form = document.querySelector(".contact-form");
var formData = new FormData(form);
fetch(form.action, {
method: "POST",
body: formData
})
.then(response => response.json())
.then(data => {
// Display alert based on the response
if (data.status === "success") {
// Success alert
Swal.fire({
icon: 'success',
title: 'Success!',
text: 'Email sent successfully!',
}).then(() => {
// Reload the page
window.location.reload();
});
} else {
// Error alert
Swal.fire({
icon: 'error',
title: 'Error!',
text: 'Error sending email. Please try again.',
});
}
})
.catch(error => {
console.error("Error:", error);
// Unexpected error alert
Swal.fire({
icon: 'error',
title: 'Error!',
text: 'An unexpected error occurred. Please try again.',
});
});
});
});