-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
137 lines (123 loc) · 5.54 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
document.addEventListener("DOMContentLoaded", () => {
const card = document.querySelector(".pixel-border-card");
const circles = document.querySelectorAll(".circle");
const timelineLine = document.querySelector(".timeline-line");
const cardsData = [
{title:"CruzRoja",text:"blablabla",tags:["Tobar","Teleco","Tag1"]},
{title:"AyudanteTulon",text:"blablabla",tags:["LaTex","tag2","tag1"]},
{title:"Tutor",text:"blablabla",tags:["EDA","tag2","tag1"]},
{title:"MesaEstudio",text:"blablabla",tags:["tag3","tag2","tag1"]}
];
circles.forEach((circle, index) => {
circle.addEventListener("click", (e) => {
e.stopPropagation();
circles.forEach(c => c.classList.remove("active-circle"));
circle.classList.add("active-circle");
const data = cardsData[index];
card.querySelector("h5").textContent = data.title;
card.querySelector("p").textContent = data.text;
const badges = card.querySelectorAll(".badge");
badges.forEach(badge => badge.remove());
data.tags.forEach((tag, tagIndex) => {
const badge = document.createElement("div");
badge.className = "badge bg-dark";
if (tagIndex !== data.tags.length - 1) badge.classList.add("mb-2");
badge.textContent = tag;
card.querySelector("p").after(badge);
});
const container = document.querySelector(".timeline-container");
const containerRect = container.getBoundingClientRect();
const circleRect = circle.getBoundingClientRect();
const circleCenterX = circleRect.left - containerRect.left + circleRect.width/2;
card.style.display = "block";
card.classList.add("active-card");
const cardWidth = card.offsetWidth;
if(index === 0) {
card.style.left = `${circleCenterX}px`;
card.style.right = "auto";
card.style.transform = "none";
} else if(index === 3) {
card.style.right = `${containerRect.width - circleCenterX}px`;
card.style.left = "auto";
card.style.transform = "none";
} else {
card.style.left = `${circleCenterX - 125}px`;
card.style.right = "auto";
card.style.transform = "none";
}
timelineLine.style.marginTop = "240px";
});
});
document.addEventListener("click", (e) => {
const clickedSkill = e.target.closest('.skill-block');
const clickedCircle = e.target.closest('.circle');
const clickedCard = e.target.closest('.pixel-border-card');
if (!clickedSkill && !clickedCircle && !clickedCard) {
document.querySelectorAll('.skill-block').forEach(b => b.classList.remove('clicked'));
document.querySelectorAll('.text-insert').forEach(t => t.classList.remove('active'));
document.querySelectorAll('.skills-grid-container').forEach(c => c.style.gridGap = '4px');
circles.forEach(c => c.classList.remove("active-circle"));
card.style.display = "none";
card.classList.remove("active-card");
timelineLine.style.marginTop = "0";
}
});
circles[0].click();
});
document.querySelectorAll('.skill-block').forEach(block => {
block.addEventListener('click', function(e) {
e.stopPropagation();
const container = this.closest('.skills-grid-container');
const isMobile = window.innerWidth < 768;
let textInsert = container.querySelector('.text-insert');
if (!textInsert) {
textInsert = document.createElement('div');
textInsert.className = 'text-insert';
if (!isMobile) container.children[3].after(textInsert);
else container.append(textInsert);
}
if (isMobile) {
const allSkills = Array.from(container.querySelectorAll('.skill-block'));
const index = allSkills.indexOf(this);
const containerRect = container.getBoundingClientRect();
const gridGap = 8;
let topPos = 0;
let bottomPos = 0;
if (index === 0) {
const currentRect = this.getBoundingClientRect();
const nextRect = allSkills[1].getBoundingClientRect();
topPos = currentRect.top - containerRect.top;
bottomPos = nextRect.bottom - containerRect.top;
} else if (index === allSkills.length - 1) {
const currentRect = this.getBoundingClientRect();
const prevRect = allSkills[index-1].getBoundingClientRect();
topPos = prevRect.top - containerRect.top;
bottomPos = currentRect.bottom - containerRect.top;
} else {
const prevRect = allSkills[index-1].getBoundingClientRect();
const nextRect = allSkills[index+1].getBoundingClientRect();
topPos = prevRect.top + (prevRect.height/2) - containerRect.top;
bottomPos = nextRect.top + (nextRect.height/2) - containerRect.top;
}
textInsert.style.top = `${topPos}px`;
textInsert.style.height = `${bottomPos - topPos}px`;
}
const wasActive = this.classList.contains('clicked');
document.querySelectorAll('.text-insert').forEach(t => t.classList.remove('active'));
document.querySelectorAll('.skill-block').forEach(b => b.classList.remove('clicked'));
if (!wasActive) {
this.classList.add('clicked');
textInsert.textContent = "skillname (placeholder): " + this.querySelector('.skill-name').textContent;
textInsert.classList.add('active');
if (!isMobile) container.style.gridGap = '24px';
} else {
if (!isMobile) container.style.gridGap = '4px';
}
});
});
window.addEventListener('resize', () => {
if (window.innerWidth >= 768) {
document.querySelectorAll('.text-insert').forEach(t => t.remove());
document.querySelectorAll('.skill-block').forEach(b => b.classList.remove('clicked'));
}
});