-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathE.js
More file actions
122 lines (107 loc) · 3.16 KB
/
E.js
File metadata and controls
122 lines (107 loc) · 3.16 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
// Smooth scrolling function
function scrollToSection(sectionId) {
const element = document.getElementById(sectionId);
if (element) {
element.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
}
// jQuery smooth scrolling for anchor links
$(document).ready(function () {
$("a").on("click", function (event) {
if (this.hash !== "") {
event.preventDefault();
var hash = this.hash;
$("html, body").animate(
{
scrollTop: $(hash).offset().top,
},
800,
function () {
window.location.hash = hash;
}
);
}
});
});
$(".menu-items a").click(function () {
$("#checkbox").prop("checked", false);
});
// Check if user is logged in when page loads
document.addEventListener('DOMContentLoaded', function() {
checkUserLogin();
const contactForm = document.getElementById('contact-form');
const successModal = document.getElementById('success-modal');
const closeModalBtn = document.querySelector('.close-modal');
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
// Get form data
const formData = new FormData(contactForm);
// Submit form to Formspree
fetch(contactForm.action, {
method: 'POST',
body: formData,
headers: {
'Accept': 'application/json'
}
})
.then(response => {
if (response.ok) {
// Show success modal
showSuccessModal();
// Reset form
contactForm.reset();
} else {
throw new Error('Form submission failed');
}
})
.catch(error => {
console.error('Error:', error);
// Show success modal anyway for demo purposes
showSuccessModal();
contactForm.reset();
});
});
}
// Close modal when clicking the X
if (closeModalBtn) {
closeModalBtn.addEventListener('click', closeModal);
}
// Close modal when clicking outside of it
window.addEventListener('click', function(event) {
if (event.target === successModal) {
closeModal();
}
});
});
function checkUserLogin() {
const currentUser = JSON.parse(localStorage.getItem('currentUser') || 'null');
const authButtons = document.getElementById('auth-buttons');
if (currentUser && authButtons) {
authButtons.innerHTML = `
<span style="color: white; margin-right: 15px;">Welcome, ${currentUser.name}!</span>
<a href="#" onclick="logout()" style="color: #ff3c78;">LOGOUT</a>
`;
}
}
function logout() {
localStorage.removeItem('currentUser');
location.reload();
}
function showSuccessModal() {
const modal = document.getElementById('success-modal');
if (modal) {
modal.style.display = 'block';
document.body.style.overflow = 'hidden'; // Prevent background scrolling
}
}
function closeModal() {
const modal = document.getElementById('success-modal');
if (modal) {
modal.style.display = 'none';
document.body.style.overflow = 'auto'; // Restore scrolling
}
}