-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
200 lines (172 loc) · 6.62 KB
/
script.js
File metadata and controls
200 lines (172 loc) · 6.62 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
193
194
195
196
197
198
199
200
// Add smooth scrolling for navigation links
document.querySelectorAll("nav a").forEach(link => {
link.addEventListener("click", function (event) {
event.preventDefault(); // Prevent default link behavior
const targetId = this.getAttribute("href").substring(1); // Get the target ID
const targetElement = document.getElementById(targetId);
if (targetElement) {
targetElement.scrollIntoView({
behavior: "smooth", // Smooth scrolling
block: "start" // Align to the top of the target
});
}
});
});
// Initialize EmailJS with your User ID
(function() {
emailjs.init("UaWgwYuxDOA5dtpHE"); // public key
})();
// Create notification function
function showNotification(message, type) {
// Remove existing notification if any
const existingNotif = document.querySelector('.notification');
if (existingNotif) {
existingNotif.remove();
}
// Create notification element
const notification = document.createElement('div');
notification.className = `notification ${type}`;
notification.textContent = message;
// Add styles
notification.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
padding: 15px 20px;
border-radius: 8px;
color: white;
font-weight: bold;
z-index: 1000;
transform: translateX(100%);
transition: transform 0.3s ease;
max-width: 300px;
word-wrap: break-word;
`;
// Set background color based on type
if (type === 'success') {
notification.style.backgroundColor = '#4CAF50';
} else if (type === 'error') {
notification.style.backgroundColor = '#f44336';
} else {
notification.style.backgroundColor = '#2196F3';
}
// Add to page
document.body.appendChild(notification);
// Animate in
setTimeout(() => {
notification.style.transform = 'translateX(0)';
}, 100);
// Remove after 4 seconds
setTimeout(() => {
notification.style.transform = 'translateX(100%)';
setTimeout(() => {
if (notification.parentNode) {
notification.parentNode.removeChild(notification);
}
}, 300);
}, 4000);
}
document.getElementById('contact-form').addEventListener('submit', function(event) {
event.preventDefault();
// Get current time
const now = new Date();
const timeString = now.toLocaleString();
// Get form values - matching your template parameters
const formData = {
title: document.getElementById('title').value,
name: document.getElementById('name').value,
time: timeString,
message: document.getElementById('message').value,
email: document.getElementById('email').value
};
console.log("Sending email with data:", formData);
// Send email
emailjs.send('service_banana', 'template_b8xluse', formData)
.then(function(response) {
console.log("Email sent successfully:", response);
document.getElementById('contact-form').reset();
// Reset floating labels
document.querySelectorAll('.input').forEach(input => {
input.value = '';
});
// Show success notification
showNotification('Message sent successfully!', 'success');
}, function(error) {
console.error("Failed to send email:", error);
// Show error notification
showNotification('Failed to send message. Please try again.', 'error');
console.error('EmailJS Error:', error);
});
});
// Copy email function
function copyEmail() {
const emailText = 'fcastro02004@gmail.com';
const tooltip = document.getElementById('email-tooltip');
navigator.clipboard.writeText(emailText).then(function() {
// Show copied feedback
tooltip.textContent = 'Copied!';
tooltip.style.background = '#4CAF50';
// Reset after 2 seconds
setTimeout(function() {
tooltip.textContent = 'Click to copy';
tooltip.style.background = '#333';
}, 2000);
}).catch(function(err) {
console.error('Failed to copy email: ', err);
// Fallback for older browsers
const textArea = document.createElement('textarea');
textArea.value = emailText;
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
// Show copied feedback
tooltip.textContent = 'Copied!';
tooltip.style.background = '#4CAF50';
setTimeout(function() {
tooltip.textContent = 'Click to copy';
tooltip.style.background = '#333';
}, 2000);
});
}
document.addEventListener('DOMContentLoaded', function() {
// Email tooltip hover functionality
const emailText = document.getElementById('email-text');
const tooltip = document.getElementById('email-tooltip');
emailText.addEventListener('mouseenter', function() {
tooltip.style.opacity = '1';
});
emailText.addEventListener('mouseleave', function() {
tooltip.style.opacity = '0';
});
// Mobile menu functionality
const mobileMenuToggle = document.querySelector('.mobile-menu-toggle');
const mobileSideNav = document.querySelector('.mobile-side-nav');
const closeBtn = document.querySelector('.close-btn');
mobileMenuToggle.addEventListener('click', function() {
mobileSideNav.classList.add('open');
});
closeBtn.addEventListener('click', function() {
mobileSideNav.classList.remove('open');
});
// Close menu when clicking on a link
const mobileLinks = document.querySelectorAll('.mobile-side-nav a');
mobileLinks.forEach(link => {
link.addEventListener('click', function() {
mobileSideNav.classList.remove('open');
});
});
// Smooth scrolling for all snap links
document.querySelectorAll('.snap-link').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const targetElement = document.querySelector(targetId);
if (targetElement) {
targetElement.scrollIntoView({
behavior: 'smooth'
});
}
});
});
});