-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
462 lines (402 loc) · 17.6 KB
/
script.js
File metadata and controls
462 lines (402 loc) · 17.6 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
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
document.addEventListener('DOMContentLoaded', () => {
// usar dados globais se presentes (data.js)
const projects = window.projects || {};
const equipe = window.equipe || [];
const projetosContainer = document.getElementById("projetosContainer");
const equipeContainer = document.getElementById("equipeContainer");
const filtersRoot = document.getElementById('filters');
const toggleFiltersBtn = document.getElementById('toggleFilters');
// botão para abrir/fechar painel de filtros
if (toggleFiltersBtn && filtersRoot) {
toggleFiltersBtn.addEventListener('click', () => {
const isShown = filtersRoot.classList.toggle('show');
filtersRoot.setAttribute('aria-hidden', isShown ? 'false' : 'true');
toggleFiltersBtn.setAttribute('aria-expanded', isShown ? 'true' : 'false');
});
}
// util: extrai lista única
const unique = (arr) => Array.from(new Set(arr.flat()));
// preparar conjuntos para filtros
const allTechs = unique(Object.values(projects).map(p=>p.techs || []));
const allCats = unique(Object.values(projects).map(p=>p.category ? [p.category] : []));
const allYears = unique(Object.values(projects).map(p=>p.year ? [p.year] : [])).sort((a,b)=>b-a);
// estado dos filtros
const state = { techs: new Set(), cats: new Set(), years: new Set() };
// renderiza grupo de checkboxes
function renderFilterGroup(title, items, key) {
const wrap = document.createElement('div');
wrap.className = 'filter-group';
const t = document.createElement('div');
t.style.fontWeight = 600;
t.style.marginRight = '8px';
t.textContent = title + ':';
wrap.appendChild(t);
items.forEach(item => {
const id = `f-${key}-${String(item).replace(/\s+/g,'-')}`;
const label = document.createElement('label');
const input = document.createElement('input');
input.type = 'checkbox';
input.id = id;
input.value = item;
input.addEventListener('change', (e) => {
const set = state[key];
const val = (key === 'years') ? Number(e.target.value) : e.target.value;
if (e.target.checked) set.add(val); else set.delete(val);
applyFilters();
});
const span = document.createElement('span');
span.textContent = item;
label.append(input, span);
wrap.appendChild(label);
});
return wrap;
}
// popular filtros no DOM (só se existir container)
if (filtersRoot) {
filtersRoot.innerHTML = ''; // garante estado limpo
filtersRoot.appendChild(renderFilterGroup('Ano', allYears, 'years'));
filtersRoot.appendChild(renderFilterGroup('Categoria', allCats, 'cats'));
filtersRoot.appendChild(renderFilterGroup('Tecnologias', allTechs, 'techs'));
// botão limpar
const clearBtn = document.createElement('button');
clearBtn.type = 'button';
clearBtn.textContent = 'Limpar filtros';
clearBtn.className = 'btn';
clearBtn.addEventListener('click', () => {
state.techs.clear(); state.cats.clear(); state.years.clear();
filtersRoot.querySelectorAll('input[type="checkbox"]').forEach(i=>i.checked=false);
applyFilters();
});
filtersRoot.appendChild(clearBtn);
}
// função de renderização dos projetos (aceita array de objetos ou mapa values)
function renderProjects(list) {
if (!projetosContainer) return;
projetosContainer.innerHTML = '';
const arr = Array.isArray(list) ? list : Object.values(list);
if (!arr.length) {
const p = document.createElement('p');
p.className = 'small';
p.id = 'noResults';
p.textContent = 'Nenhum projeto encontrado com os filtros selecionados.';
projetosContainer.appendChild(p);
return;
}
arr.forEach(p => {
// card conforme solicitado: nome, descrição breve, ver detalhes
const card = document.createElement('article');
card.className = 'card project-card';
const h4 = document.createElement('h4');
h4.textContent = p.title;
const desc = document.createElement('p');
desc.textContent = p.desc;
const a = document.createElement('a');
a.href = '#';
a.className = 'btn';
// achar a key do projeto para data-open
const key = Object.keys(projects).find(k => projects[k] === p);
a.setAttribute('data-open', key);
a.textContent = 'Ver detalhes';
card.append(h4, desc, a);
projetosContainer.appendChild(card);
});
}
// aplica filtros e chama render
function applyFilters() {
const selTechs = Array.from(state.techs);
const selCats = Array.from(state.cats);
const selYears = Array.from(state.years);
const filtered = Object.values(projects).filter(p => {
// tecnologies: if none selected -> pass; else must intersect
if (selTechs.length) {
const ptechs = Array.isArray(p.techs) ? p.techs : [];
const intersects = selTechs.some(t => ptechs.includes(t));
if (!intersects) return false;
}
// category
if (selCats.length && !selCats.includes(p.category)) return false;
// year
if (selYears.length && !selYears.includes(p.year)) return false;
return true;
});
renderProjects(filtered);
}
// render inicial
renderProjects(projects);
// equipe: render como foto + nome; clique abre card de membro no modal
if (equipeContainer) {
equipeContainer.innerHTML = '';
equipe.forEach(m => {
const card = document.createElement("div");
card.className = "card member";
card.style.cursor = 'pointer';
card.setAttribute('data-member', m.id);
// layout: imagem à esquerda, nome ao lado
const imgWrap = document.createElement('div');
if (m.img) {
const img = document.createElement('img');
img.loading = 'lazy';
img.src = m.img;
img.alt = m.nome;
img.style.width = '64px';
img.style.height = '64px';
img.style.borderRadius = '50%';
img.style.objectFit = 'cover';
imgWrap.appendChild(img);
}
const info = document.createElement('div');
info.style.display = 'flex';
info.style.flexDirection = 'column';
info.style.justifyContent = 'center';
info.style.marginLeft = '10px';
const nameEl = document.createElement("div");
nameEl.textContent = m.nome;
nameEl.style.fontWeight = 600;
info.appendChild(nameEl);
// assemble row
const row = document.createElement('div');
row.style.display = 'flex';
row.style.alignItems = 'center';
row.appendChild(imgWrap);
row.appendChild(info);
card.appendChild(row);
equipeContainer.appendChild(card);
});
} else {
console.warn("equipeContainer não encontrado");
}
// listener global: prioriza abertura de card de membro, depois projetos
document.addEventListener('click', (ev) => {
// abrir perfil do membro em modal
const memBtn = ev.target.closest('[data-member]');
if (memBtn) {
ev.preventDefault();
const id = Number(memBtn.getAttribute('data-member'));
const member = equipe.find(x => Number(x.id) === id);
if (!member) return;
const content = document.getElementById('modalContent');
content.innerHTML = '';
// layout: Name: (Foto) / Bio / LinkedIn / Github / Projetos relacionados
const header = document.createElement('div');
header.style.display = 'flex';
header.style.alignItems = 'flex-start';
header.style.gap = '12px';
const left = document.createElement('div');
const nameTitle = document.createElement('h2');
nameTitle.textContent = member.nome;
left.appendChild(nameTitle);
const bio = document.createElement('p');
bio.textContent = member.bio || '';
left.appendChild(bio);
// socials list (explicit labels)
const socials = document.createElement('div');
socials.style.marginTop = '8px';
// attempt to find linkedin/github by label
const linkLabels = {};
(member.links || []).forEach(l => {
const labelLower = (l.label||'').toLowerCase();
if (labelLower.includes('linkedin')) linkLabels.linkedin = l.href;
if (labelLower.includes('github')) linkLabels.github = l.href;
if (labelLower.includes('instagram')) linkLabels.instagram = l.href;
});
if (linkLabels.linkedin) {
const row = document.createElement('div');
row.innerHTML = `<strong>LinkedIn:</strong> `;
const a = document.createElement('a');
a.href = linkLabels.linkedin;
a.target = '_blank';
a.rel = 'noopener noreferrer';
a.textContent = linkLabels.linkedin;
row.appendChild(a);
socials.appendChild(row);
}
if (linkLabels.github) {
const row = document.createElement('div');
row.innerHTML = `<strong>Github:</strong> `;
const a = document.createElement('a');
a.href = linkLabels.github;
a.target = '_blank';
a.rel = 'noopener noreferrer';
a.textContent = linkLabels.github;
row.appendChild(a);
socials.appendChild(row);
}
if (linkLabels.instagram) {
const row = document.createElement('div');
row.innerHTML = `<strong>Instagram:</strong> `;
const a = document.createElement('a');
a.href = linkLabels.instagram;
a.target = '_blank';
a.rel = 'noopener noreferrer';
a.textContent = linkLabels.instagram;
row.appendChild(a);
socials.appendChild(row);
}
left.appendChild(socials);
const right = document.createElement('div');
if (member.img) {
const img = document.createElement('img');
img.src = member.img;
img.alt = member.nome;
img.loading = 'lazy';
img.style.width = '120px';
img.style.height = '120px';
img.style.objectFit = 'cover';
img.style.borderRadius = '10px';
right.appendChild(img);
}
header.appendChild(left);
header.appendChild(right);
content.appendChild(header);
// projetos relacionados
const related = Object.values(projects).filter(p => Array.isArray(p.memberIds) && p.memberIds.includes(member.id));
const projTitle = document.createElement('h3');
projTitle.textContent = 'Projetos relacionados';
projTitle.style.marginTop = '12px';
content.appendChild(projTitle);
if (!related.length) {
const p = document.createElement('p');
p.className = 'small';
p.textContent = 'Nenhum projeto relacionado.';
content.appendChild(p);
} else {
const list = document.createElement('div');
list.style.display = 'flex';
list.style.flexDirection = 'column';
list.style.gap = '8px';
related.forEach(p => {
const item = document.createElement('div');
item.className = 'card';
item.style.padding = '10px';
const t = document.createElement('div');
t.style.display = 'flex';
t.style.justifyContent = 'space-between';
const title = document.createElement('div');
title.textContent = p.title;
const btn = document.createElement('a');
btn.href = '#';
btn.className = 'btn';
const key = Object.keys(projects).find(k => projects[k] === p);
btn.setAttribute('data-open', key);
btn.textContent = 'Ver detalhes';
t.appendChild(title);
t.appendChild(btn);
item.appendChild(t);
list.appendChild(item);
});
content.appendChild(list);
}
document.getElementById('modal').classList.add('show');
return;
}
// abrir modal de projeto (existente)
const btn = ev.target.closest('[data-open]');
if (!btn) return;
ev.preventDefault();
const id = btn.getAttribute('data-open');
const p = projects[id];
if (!p) return;
const content = document.getElementById('modalContent');
content.innerHTML = '';
// nome projeto
const title = document.createElement('h2');
title.textContent = p.title;
// descrição breve
const brief = document.createElement('p');
brief.textContent = p.desc;
// participantes
const members = (Array.isArray(p.memberIds) ? p.memberIds.map(mid => {
const m = equipe.find(x => Number(x.id) === mid);
return m ? m.nome : null;
}).filter(x => x) : []);
const memTitle = document.createElement('p');
memTitle.className = 'medium';
memTitle.innerHTML = '<strong>Participantes:</strong> ' + (members.length ? members.join(', ') : 'N/A');
// categoria
const catTitle = document.createElement('p');
catTitle.className = 'small';
catTitle.innerHTML = '<strong>Categoria:</strong> ' + (p.category || 'N/A');
// tecnologias
const techTitle = document.createElement('p');
techTitle.className = 'small';
techTitle.innerHTML = '<strong>Tecnologias:</strong> ' + (Array.isArray(p.techs) ? p.techs.join(', ') : p.techs || '');
// ano
const yearTitle = document.createElement('p');
yearTitle.className = 'small';
yearTitle.innerHTML = '<strong>Ano:</strong> ' + (p.year || 'N/A');
// abrir repositório
const repoWrap = document.createElement('p');
repoWrap.style.marginTop = '12px';
const repoLink = document.createElement('a');
repoLink.className = 'btn';
repoLink.textContent = 'Abrir repositório';
repoLink.href = p.repo || '#';
repoLink.target = '_blank';
repoLink.rel = 'noopener noreferrer';
repoWrap.appendChild(repoLink);
content.append(title, memTitle, brief, catTitle, techTitle, yearTitle, repoWrap);
document.getElementById('modal').classList.add('show');
});
// fechar modal
const closeModal = document.getElementById('closeModal');
if (closeModal) closeModal.addEventListener('click', ()=>document.getElementById('modal').classList.remove('show'));
const modal = document.getElementById('modal');
if (modal) modal.addEventListener('click', (e)=>{ if (e.target.id === 'modal') modal.classList.remove('show'); });
// Form validation e envio simulado (mantido)
const form = document.getElementById('contactForm');
const status = document.getElementById('status');
if (form && status) {
form.addEventListener('submit', (ev)=>{
ev.preventDefault();
status.textContent = '';
const nome = form.nome.value.trim();
const email = form.email.value.trim();
const mensagem = form.mensagem.value.trim();
if(!nome || !email || !mensagem){ status.textContent = 'Preencha todos os campos obrigatórios.'; return }
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if(!re.test(email)){ status.textContent = 'Email com formato inválido.'; return }
status.textContent = 'Enviando...';
setTimeout(()=>{
status.textContent = 'Mensagem enviada com sucesso! Obrigado.';
form.reset();
},1000);
});
}
// Smooth scroll for nav
// document.querySelectorAll('nav a').forEach(a=>{
// a.addEventListener('click', (e)=>{
// e.preventDefault();
// const id = a.getAttribute('href').replace('#','');
// const el = document.getElementById(id);
// if(el) el.scrollIntoView({behavior:'smooth',block:'start'});
// document.querySelectorAll('nav a').forEach(x=>x.classList.remove('active'));
// a.classList.add('active');
// })
// });
// Gerenciar tema claro/escuro
(function() {
const themeToggle = document.getElementById('themeToggle');
const htmlElement = document.documentElement;
// Carregar tema salvo ou usar preferência do sistema
const savedTheme = localStorage.getItem('theme') ||
(window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
const applyTheme = (theme) => {
if (theme === 'dark') {
document.body.classList.add('dark-theme');
themeToggle.textContent = '🌤️';
localStorage.setItem('theme', 'dark');
} else {
document.body.classList.remove('dark-theme');
themeToggle.textContent = '🌙';
localStorage.setItem('theme', 'light');
}
};
// Aplicar tema inicial
applyTheme(savedTheme);
// Alternar tema ao clicar
themeToggle.addEventListener('click', () => {
const currentTheme = document.body.classList.contains('dark-theme') ? 'dark' : 'light';
applyTheme(currentTheme === 'dark' ? 'light' : 'dark');
});
})();
});