-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
151 lines (135 loc) · 5.67 KB
/
Copy pathscript.js
File metadata and controls
151 lines (135 loc) · 5.67 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
document.addEventListener('DOMContentLoaded', () => {
// --- Theme Toggle ---
const themeToggleButton = document.getElementById('theme-toggle');
const doc = document.documentElement;
// Apply the saved theme on page load
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'light') {
doc.setAttribute('data-theme', 'light');
}
// Handle toggle button click
themeToggleButton.addEventListener('click', () => {
// Check if the data-theme attribute currently exists
const isLight = doc.hasAttribute('data-theme');
if (isLight) {
// If it's light (attribute exists), switch to dark by removing the attribute
doc.removeAttribute('data-theme');
localStorage.setItem('theme', 'dark');
} else {
// If it's dark (no attribute), switch to light by adding the attribute
doc.setAttribute('data-theme', 'light');
localStorage.setItem('theme', 'light');
}
});
// --- Navbar Scroll Effect ---
const navbar = document.querySelector('.navbar');
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
});
// --- Back to Top Button ---
const backToTopButton = document.getElementById('back-to-top');
window.addEventListener('scroll', () => {
if (window.scrollY > 300) {
backToTopButton.classList.add('visible');
} else {
backToTopButton.classList.remove('visible');
}
});
backToTopButton.addEventListener('click', (e) => {
e.preventDefault();
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
// --- Mobile Hamburger Menu ---
const hamburger = document.querySelector(".hamburger");
const navMenuWrapper = document.querySelector(".nav-menu-wrapper");
hamburger.addEventListener("click", () => {
hamburger.classList.toggle("active");
navMenuWrapper.classList.toggle("active");
});
document.querySelectorAll(".nav-link").forEach(link => {
link.addEventListener("click", () => {
if (hamburger.classList.contains('active')) {
hamburger.classList.remove("active");
navMenuWrapper.classList.remove("active");
}
});
});
// --- Typed.js for Hero Section ---
if (document.getElementById('typed-text')) {
new Typed('#typed-text', {
strings: ['Java.', 'Python.', 'C#.', 'Modern Web Tech.'],
typeSpeed: 50,
backSpeed: 30,
backDelay: 1500,
loop: true
});
}
// --- Tech Stack Animation ---
const techContainer = document.querySelector('.tech-container');
if (techContainer) {
const content = Array.from(techContainer.children);
content.forEach(item => {
techContainer.appendChild(item.cloneNode(true));
});
}
// --- Live Email Validation ---
const emailInput = document.getElementById('email');
const emailValidationMessage = document.querySelector('.email-validation-message');
if (emailInput) {
emailInput.addEventListener('input', () => {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (emailInput.value === "") {
emailValidationMessage.textContent = "";
emailValidationMessage.className = 'email-validation-message';
} else if (emailRegex.test(emailInput.value)) {
emailValidationMessage.textContent = "Valid email";
emailValidationMessage.className = 'email-validation-message valid';
} else {
emailValidationMessage.textContent = "Invalid email format";
emailValidationMessage.className = 'email-validation-message invalid';
}
});
}
// --- Project Modal Logic ---
const modal = document.getElementById('project-modal');
const modalCloseBtn = document.querySelector('.modal-close-btn');
const projectGrid = document.querySelector('.project-grid');
if (projectGrid && modal) {
projectGrid.addEventListener('click', (e) => {
const detailsButton = e.target.closest('.btn-details');
if (detailsButton) {
const card = detailsButton.closest('.project-card');
// Populate modal
modal.querySelector('.modal-title').textContent = card.dataset.title;
modal.querySelector('.modal-img').src = card.dataset.img;
modal.querySelector('.modal-desc').textContent = card.dataset.desc;
modal.querySelector('.modal-link').href = card.dataset.link;
const techStackContainer = modal.querySelector('.modal-tech-stack');
techStackContainer.innerHTML = ''; // Clear previous tags
const techs = card.dataset.tech.split(',');
techs.forEach(tech => {
const techTag = document.createElement('span');
techTag.className = 'tech-tag';
techTag.textContent = tech;
techStackContainer.appendChild(techTag);
});
// Show modal
modal.classList.add('visible');
}
});
// Close modal
modalCloseBtn.addEventListener('click', () => modal.classList.remove('visible'));
modal.addEventListener('click', (e) => {
if (e.target === modal) {
modal.classList.remove('visible');
}
});
}
});