-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
236 lines (189 loc) · 7.56 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
// Dark Mode button
let isDarkMode = false;
const toggleDarkModeButtonXl = document.getElementById('toggleDarkModeXl');
const modeIconXl = document.getElementById('mode-icon-xl');
const toggleDarkModeButtonLg = document.getElementById('toggleDarkModeLg');
const modeIconLg = document.getElementById('mode-icon-lg');
const toggleDarkModeButtonSm = document.getElementById('toggleDarkModeSm');
const modeIconSm = document.getElementById('mode-icon-sm');
const body = document.body;
const danny = document.getElementById('danny');
const topBars = document.querySelectorAll('.top-bar-div');
const allPills = document.querySelectorAll('.pill-button');
const whiteBoxes = document.querySelectorAll('.white-box');
const resumeButtons = document.querySelectorAll('.resume-button');
const contact = document.getElementById('contact-form');
const whiteBackgrounds = document.querySelectorAll('.white-bg');
const lightIconLg = document.getElementById('light-mode-icons-lg');
const darkIconLg = document.getElementById('dark-mode-icons-lg');
const lightIconMd = document.getElementById('light-mode-icons-md');
const darkIconMd = document.getElementById('dark-mode-icons-md');
toggleDarkModeButtonXl.addEventListener('click', () => {
isDarkMode = !isDarkMode;
isDarkMode ? modeIconXl.src='assets/light-mode.png' : modeIconXl.src='assets/dark-mode.png';
toggleDarkMode();
});
toggleDarkModeButtonLg.addEventListener('click', () => {
isDarkMode = !isDarkMode;
isDarkMode ? modeIconLg.src='assets/light-mode.png' : modeIconLg.src='assets/dark-mode.png';
toggleDarkMode();
});
toggleDarkModeButtonSm.addEventListener('click', () => {
isDarkMode = !isDarkMode;
isDarkMode ? modeIconSm.src='assets/light-mode.png' : modeIconSm.src='assets/dark-mode.png';
toggleDarkMode();
});
function toggleDarkMode() {
body.classList.toggle('light');
body.classList.toggle('dark');
danny.classList.toggle('text-blue-400');
topBars.forEach(bar => {
bar.classList.toggle('skyblue');
bar.classList.toggle('dark-top-bar');
})
allPills.forEach(pill => {
pill.classList.toggle('text-black');
})
resumeButtons.forEach(button => {
button.classList.toggle('text-black');
})
whiteBoxes.forEach(box => {
box.classList.toggle('white-shadow');
})
whiteBackgrounds.forEach(bg => {
bg.classList.toggle('white-bg');
bg.classList.toggle('black-bg');
})
contact.classList.toggle('bg-white');
contact.classList.toggle('bg-gray-400');
contact.classList.toggle('text-black');
lightIconLg.classList.toggle('lg:flex');
darkIconLg.classList.toggle('lg:flex');
lightIconMd.classList.toggle('flex');
lightIconMd.classList.toggle('hidden');
darkIconMd.classList.toggle('flex');
darkIconMd.classList.toggle('hidden');
}
// Toggle Hamburger Menu
function toggleMenu() {
var menu = document.getElementById('burger-links');
var bar1 = document.getElementById('bar1');
var bar2 = document.getElementById('bar2');
var bar3 = document.getElementById('bar3');
menu.classList.toggle('hidden');
bar1.classList.toggle('opened');
bar2.classList.toggle('opened');
bar3.classList.toggle('opened');
}
document.getElementById('hamburger-icon').addEventListener('click', toggleMenu);
// Type Animation in Home Page
document.addEventListener('DOMContentLoaded', function() {
new Typed(".auto-typed", {
strings: ["Full Stack Developer", "Problem Solver", "Lifelong Learner"],
typeSpeed: 70,
backSpeed: 40,
loop: true
});
});
// Smooth Scroll
document.addEventListener('DOMContentLoaded', function () {
function scrollToTarget(target) {
const targetElement = document.querySelector(target);
if (targetElement) {
const offset = document.querySelector('.fixed').offsetHeight;
window.scrollTo({
top: targetElement.offsetTop - offset,
behavior: 'smooth'
});
}
}
document.querySelectorAll('#burger-links a').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const targetSection = this.getAttribute('href');
scrollToTarget(targetSection);
});
});
document.querySelectorAll('#nav-links a').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const targetSection = this.getAttribute('href');
scrollToTarget(targetSection);
});
});
document.querySelectorAll('#top-bar a').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const targetSection = this.getAttribute('href');
scrollToTarget(targetSection);
});
});
const contactLink = document.getElementById('contact-link');
contactLink.addEventListener('click', function (e) {
e.preventDefault();
const targetSection = '#contact';
scrollToTarget(targetSection);
});
const contactLink2 = document.getElementById('contact-link2');
contactLink2.addEventListener('click', function (e) {
e.preventDefault();
const targetSection = '#contact';
scrollToTarget(targetSection);
});
});
// for Technical Project page, toggle description and testimony
document.addEventListener('DOMContentLoaded', function () {
const descriptionLink = document.getElementById('description-link');
const testimonyLink = document.getElementById('testimony-link');
const descriptionDiv = document.getElementById('description');
const testimonyDiv = document.getElementById('testimony');
descriptionLink.addEventListener('click', function () {
toggleVisibility(descriptionDiv, testimonyDiv, testimonyLink, descriptionLink);
});
testimonyLink.addEventListener('click', function () {
toggleVisibility(testimonyDiv, descriptionDiv, descriptionLink, testimonyLink);
});
function toggleVisibility(showDiv, hideDiv, showLink, hideLink) {
showDiv.classList.remove('hidden');
hideDiv.classList.add('hidden');
showLink.classList.remove('hidden');
hideLink.classList.add('hidden');
}
});
// For Contact Form
const liveEndPoint = '/.netlify/functions';
// const liveEndPoint = 'http://localhost:3000'
const contactForm = document.querySelector('#contact-form');
let inputName = document.getElementById('name');
let inputPhone = document.getElementById('phone');
let inputEmail = document.getElementById('email');
let inputCompany = document.getElementById('company');
let inputMessage = document.getElementById('message');
contactForm.addEventListener('submit', async (e) => {
e.preventDefault();
let formData = {
name: inputName.value,
phone: inputPhone.value,
email: inputEmail.value,
company: inputCompany.value,
message: inputMessage.value,
};
console.log(formData);
try {
const response = await axios.post(`${liveEndPoint}/contact`, formData);
console.log(response.data);
if(response.data.message === 'success') {
alert('Email sent! Thank you for your inquiry!');
inputName.value = '';
inputPhone.value = '';
inputEmail.value = '';
inputCompany.value = '';
inputMessage.value = '';
} else {
alert('Something went wrong... please try again later');
}
} catch (error) {
console.error('Error:', error);
alert('Something went wrong... please try again later');
}
});