-
Notifications
You must be signed in to change notification settings - Fork 159
/
roadmaps.js
68 lines (55 loc) · 2.3 KB
/
roadmaps.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
(async function render() {
await loadRoadmapJson();
})();
async function loadRoadmapJson() {
try {
const resp = await fetch("index.json");
if (resp.ok) {
const roadmaps = await resp.json();
roadmaps.forEach((roadmapStep, index) => {
let justifySide = index % 2 == 0 ? 'start' : 'end';
justifySide = justifySide == 'start' ? 1 : 2
let animationDelay = 1;
createStep(roadmapStep, justifySide, animationDelay);
if (animationDelay < 3) animationDelay++;
if (roadmapStep.additionalContents) {
roadmapStep.additionalContents.forEach(nextContent => {
createStep(nextContent, justifySide, animationDelay);
if (animationDelay < 3) animationDelay++;
});
}
});
}
} catch (error) {
console.log(`Erro ao carregar o arquivo JSON de Roadmap: ${error}`);
}
}
function createStep(content, justify, delay) {
const htmlTemplate = `
<div class="row row-${justify} animate pop delay-${delay}">
<section>
${createIconIfNecessary(content.iconClasses)}
${createTitleIfNecessary(content.name)}
${createDescriptionIfNecessary(content.description)}
${createLinkIfNecessary(content.link)}
</section>
</div>
`;
// https://stackoverflow.com/a/35385518
var template = document.createElement('template');
template.innerHTML = htmlTemplate.trim();
const step = template.content.firstChild;
document.querySelector(".roadmap-steps").appendChild(step);
}
function createIconIfNecessary(icons) {
return icons ? `<i class="icon ${icons}"></i>` : '';
}
function createTitleIfNecessary(title) {
return title ? `<div class="details"><span class="title">${title}</span></div>` : '';
}
function createDescriptionIfNecessary(description) {
return description ? `<p>${description}</p>` : '';
}
function createLinkIfNecessary(link) {
return link ? `<div class="bottom"><a href="${link}" target="_blank">Saiba Mais</a></div>` : '';
}