-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
186 lines (157 loc) · 6.71 KB
/
Copy pathscript.js
File metadata and controls
186 lines (157 loc) · 6.71 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
// Improved navigation with smooth scrolling
document.addEventListener('DOMContentLoaded', function() {
// Get all navigation links
const navLinks = document.querySelectorAll('.nav-menu a');
// Add click event listener to each link
navLinks.forEach(link => {
link.addEventListener('click', function(event) {
event.preventDefault();
// Get the target section ID
const targetId = this.getAttribute('href').substring(1);
const targetSection = document.getElementById(targetId);
// If target section exists, scroll to it smoothly
if (targetSection) {
window.scrollTo({
top: targetSection.offsetTop,
behavior: 'smooth'
});
}
});
});
// Mobile navigation toggle
const navToggle = document.querySelector('.bars');
const dropdownList = document.querySelector('.dropdown-list');
if (navToggle) {
navToggle.addEventListener('click', function() {
if (dropdownList.style.display === 'block') {
dropdownList.style.display = 'none';
} else {
dropdownList.style.display = 'block';
}
});
}
// Close mobile nav when clicking on a link
const mobileNavLinks = document.querySelectorAll('.dropdown-list a');
mobileNavLinks.forEach(link => {
link.addEventListener('click', function() {
if (window.innerWidth <= 768) {
dropdownList.style.display = 'none';
}
});
});
// Initialize skill animation
initSkillAnimation();
// Initialize contact form validation
initContactForm();
});
// Initialize project filters — called after async render with the live projects array
function initProjectFilters(projects) {
const filterContainer = document.getElementById('project-filters');
if (filterContainer) {
const techTags = new Set();
projects.forEach(project => {
project.techStack.forEach(tech => techTags.add(tech));
});
let filterHTML = '<button class="filter-btn active" data-filter="all">All</button>';
techTags.forEach(tech => {
filterHTML += `<button class="filter-btn" data-filter="${tech}">${tech}</button>`;
});
filterContainer.innerHTML = filterHTML;
const filterBtns = document.querySelectorAll('.filter-btn');
filterBtns.forEach(btn => {
btn.addEventListener('click', function() {
filterBtns.forEach(b => b.classList.remove('active'));
this.classList.add('active');
const filter = this.getAttribute('data-filter');
document.querySelectorAll('.portfolio-item').forEach(item => {
if (filter === 'all') {
item.style.display = 'flex';
} else {
const projectId = item.getAttribute('data-id');
const project = projects.find(p => p.id === projectId);
item.style.display = (project && project.techStack.includes(filter)) ? 'flex' : 'none';
}
});
});
});
}
}
// Animate skill bars on scroll
function initSkillAnimation() {
const skills = document.querySelector('.skills-display');
if (skills) {
const skillBars = document.querySelectorAll('.skill-progress > div');
// Reset skill bars initially
skillBars.forEach(bar => {
bar.style.width = '0';
});
// Animate skill bars when they come into view
window.addEventListener('scroll', function() {
const skillsPosition = skills.getBoundingClientRect().top;
const windowHeight = window.innerHeight;
if (skillsPosition < windowHeight - 100) {
skillBars.forEach(bar => {
// Get the width class from the bar
const classes = bar.className.split(' ');
let width = '80%'; // Default width
if (classes.includes('eighty-five-percent')) {
width = '85%';
} else if (classes.includes('eighty-percent')) {
width = '80%';
} else if (classes.includes('fifty-percent')) {
width = '50%';
}
// Animate the width
bar.style.width = width;
bar.style.transition = 'width 1s ease-in-out';
});
}
});
}
}
// Contact form with Formspree integration
// Sign up at https://formspree.io and replace YOUR_FORM_ID below
const FORMSPREE_ENDPOINT = 'https://formspree.io/f/YOUR_FORM_ID';
function initContactForm() {
const contactForm = document.getElementById('contact-form');
const submitBtn = contactForm ? contactForm.querySelector('button[type="submit"]') : null;
if (contactForm) {
contactForm.addEventListener('submit', function(event) {
event.preventDefault();
const name = document.getElementById('input-name').value.trim();
const email = document.getElementById('input-email').value.trim();
const message = document.getElementById('input-message').value.trim();
if (!name || !email || !message) {
alert('Please fill in all fields');
return;
}
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
alert('Please enter a valid email address');
return;
}
submitBtn.textContent = 'SENDING...';
submitBtn.disabled = true;
fetch(FORMSPREE_ENDPOINT, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' },
body: JSON.stringify({ name, email, message })
})
.then(response => {
if (response.ok) {
alert('Thank you for your message! I will get back to you soon.');
contactForm.reset();
} else {
alert('Something went wrong. Please try emailing me directly.');
}
})
.catch(() => {
alert('Something went wrong. Please try emailing me directly.');
})
.finally(() => {
submitBtn.textContent = 'SEND MESSAGE';
submitBtn.disabled = false;
});
});
}
}