-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
177 lines (147 loc) · 5.9 KB
/
script.js
File metadata and controls
177 lines (147 loc) · 5.9 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
/* Navigation */
function go(path) {
window.location.href = path;
}
/* Open GitHub code */
function openCode(url) {
window.open(url, "_blank");
}
/* Render category cards (home page) */
function renderCategories(list) {
const container = document.getElementById("categories");
if (!container) return;
container.innerHTML = "";
list.forEach(cat => {
const card = document.createElement("div");
card.className = "group cursor-pointer";
card.dataset.title = cat.dataTitle;
card.onclick = () => go(cat.url);
card.innerHTML = `
<div class="relative bg-white/5 backdrop-blur-lg border border-purple-400/20 rounded-2xl p-8 transform transition-all duration-500 hover:scale-105 hover:bg-white/10 hover:border-purple-400/50 hover:shadow-2xl hover:shadow-purple-500/30">
<div class="absolute inset-0 bg-gradient-to-br ${cat.gradientFrom} ${cat.gradientTo} opacity-0 group-hover:opacity-100 rounded-2xl transition-opacity duration-500"></div>
<div class="relative z-10">
<div class="text-5xl mb-6 transform group-hover:scale-110 transition-transform duration-300">
<i class="${cat.icon} ${cat.iconColor}"></i>
</div>
<h4 class="text-2xl font-bold text-white mb-2">${cat.title}</h4>
<p class="text-gray-400 text-sm">${cat.desc}</p>
</div>
</div>
`;
container.appendChild(card);
});
}
/* Render projects (used in project pages) */
function renderProjects(list) {
const container = document.getElementById("projects");
if (!container) return;
container.innerHTML = "";
list.forEach(p => {
const card = document.createElement("div");
card.className = "group cursor-pointer";
card.dataset.title = p.title.toLowerCase();
card.innerHTML = `
<div class="relative h-full bg-white/5 backdrop-blur-lg border border-purple-400/20 rounded-2xl p-6 transform transition-all duration-500 hover:scale-105 hover:bg-white/10 hover:border-purple-400/50 hover:shadow-2xl hover:shadow-purple-500/30">
<div class="absolute inset-0 bg-gradient-to-br from-blue-500/20 to-purple-600/20 opacity-0 group-hover:opacity-100 rounded-2xl transition-opacity duration-500"></div>
<div class="relative z-10 flex flex-col h-full">
<div class="text-4xl mb-4 transform group-hover:scale-110 transition-transform duration-300">
<i class="fa-solid ${p.icon} text-purple-400"></i>
</div>
<h4 class="text-xl font-bold text-white mb-2">${p.title}</h4>
${p.desc ? `<p class="text-gray-400 text-sm mb-4 flex-grow">${p.desc}</p>` : '<div class="flex-grow"></div>'}
<div class="flex gap-3 mt-auto">
<button class="live-btn flex-1 px-4 py-2 bg-gradient-to-r from-blue-500 to-purple-600 text-white font-semibold rounded-lg hover:scale-105 transition-all duration-300 hover:shadow-lg hover:shadow-purple-500/50">
Live
</button>
<button class="code-btn flex-1 px-4 py-2 border-2 border-purple-400 text-purple-300 font-semibold rounded-lg hover:bg-purple-400 hover:text-white transition-all duration-300">
Code
</button>
</div>
</div>
</div>
`;
// Use event listeners instead of onclick
card.querySelector(".live-btn").addEventListener("click", () => go(p.live));
card.querySelector(".code-btn").addEventListener("click", () => openCode(p.code));
container.appendChild(card);
});
}
/* Search (Home page categories) */
function searchProjects() {
const searchInput = document.getElementById("search");
if (!searchInput) return; // Safety check
const input = searchInput.value.toLowerCase();
const cards = document.querySelectorAll("[data-title]");
cards.forEach(card => {
const title = card.dataset.title || card.innerText.toLowerCase();
card.style.display = title.includes(input) ? "" : "none"; // Use empty string for default display
});
}
const headings = document.querySelectorAll("h2");
const observer = new IntersectionObserver(
entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add("reveal");
}
});
},
{ threshold: 0.6 }
);
headings.forEach(h => observer.observe(h));
/* Initialize on page load */
document.addEventListener("DOMContentLoaded", async () => {
// Load categories on home page
const categoriesContainer = document.getElementById("categories");
if (categoriesContainer) {
try {
const res = await fetch('/data/categories.json');
const categories = await res.json();
renderCategories(categories);
} catch (err) {
console.error('Failed to load categories:', err);
}
}
// Trigger search to ensure cards are visible
const searchInput = document.getElementById("search");
if (searchInput) {
searchInput.value = "";
searchProjects();
}
// Typing animation
const texts = [
"Frontend Developer",
"Creative Coder",
"Web Designer",
"Problem Solver",
"UI/UX Enthusiast"
];
let textIndex = 0;
let charIndex = 0;
let isDeleting = false;
const typingElement = document.querySelector(".typing-text");
if (typingElement) {
function type() {
const currentText = texts[textIndex];
if (isDeleting) {
typingElement.textContent = currentText.substring(0, charIndex - 1);
charIndex--;
} else {
typingElement.textContent = currentText.substring(0, charIndex + 1);
charIndex++;
}
let typingSpeed = isDeleting ? 80 : 150;
if (!isDeleting && charIndex === currentText.length) {
typingSpeed = 2500; // Pause at end
isDeleting = true;
} else if (isDeleting && charIndex === 0) {
isDeleting = false;
textIndex = (textIndex + 1) % texts.length;
typingSpeed = 800;
}
setTimeout(type, typingSpeed);
}
// Start typing animation after header animations
setTimeout(type, 1200);
}
});