forked from alip-jmbd/PortofolioNEO
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneo.js
More file actions
115 lines (102 loc) · 4.15 KB
/
neo.js
File metadata and controls
115 lines (102 loc) · 4.15 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
document.addEventListener('DOMContentLoaded', () => {
const menuBtn = document.getElementById('menu-btn');
const closeBtn = document.getElementById('close-btn');
const navMenu = document.getElementById('nav-menu');
const navLinks = navMenu.querySelectorAll('a');
const contactForm = document.getElementById('contact-form');
const formStatus = document.getElementById('form-status');
const greetingElement = document.getElementById('dynamic-greeting');
if (menuBtn) {
menuBtn.addEventListener('click', () => {
navMenu.classList.add('is-open');
});
}
if (closeBtn) {
closeBtn.addEventListener('click', () => {
navMenu.classList.remove('is-open');
});
}
navLinks.forEach(link => {
link.addEventListener('click', () => {
if (navMenu.classList.contains('is-open')) {
navMenu.classList.remove('is-open');
}
});
});
function updateClock(element) {
if (!element) return;
const now = new Date();
const days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
const dayName = days[now.getDay()];
const date = String(now.getDate()).padStart(2, '0');
const month = String(now.getMonth() + 1).padStart(2, '0');
const year = now.getFullYear();
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
const seconds = String(now.getSeconds()).padStart(2, '0');
if (element.classList.contains('realtime-clock-chat')) {
element.innerHTML = `${hours}:${minutes}:${seconds}`;
} else {
element.innerHTML = `${dayName}, ${date}/${month}/${year}<br>${hours}:${minutes}:${seconds}`;
}
}
const clockPortfolio = document.querySelector('.realtime-clock');
const clockChat = document.querySelector('.realtime-clock-chat');
if (clockPortfolio) {
setInterval(() => updateClock(clockPortfolio), 1000);
updateClock(clockPortfolio);
}
if (clockChat) {
setInterval(() => updateClock(clockChat), 1000);
updateClock(clockChat);
}
if (greetingElement) {
const now = new Date();
const currentHour = now.getHours();
let greetingText;
if (currentHour >= 5 && currentHour < 12) {
greetingText = "Ohayou!";
} else if (currentHour >= 12 && currentHour < 18) {
greetingText = "Konnichiwa!";
} else {
greetingText = "Konbanwa!";
}
greetingElement.innerText = greetingText;
}
if (contactForm) {
contactForm.addEventListener('submit', async (e) => {
e.preventDefault();
const form = e.target;
const data = new FormData(form);
try {
const response = await fetch(form.action, {
method: form.method,
body: data,
headers: { 'Accept': 'application/json' }
});
if (response.ok) {
formStatus.innerHTML = "Thanks for your submission!";
formStatus.className = 'form-status-success';
form.reset();
} else {
const responseData = await response.json();
if (Object.hasOwn(responseData, 'errors')) {
formStatus.innerHTML = responseData["errors"].map(error => error["message"]).join(", ");
} else {
formStatus.innerHTML = "Oops! There was a problem submitting your form";
}
formStatus.className = 'form-status-error';
}
} catch (error) {
formStatus.innerHTML = "Oops! There was a problem submitting your form";
formStatus.className = 'form-status-error';
}
setTimeout(() => {
if (formStatus) {
formStatus.innerHTML = '';
formStatus.className = '';
}
}, 5000);
});
}
});