-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
58 lines (51 loc) · 1.82 KB
/
script.js
File metadata and controls
58 lines (51 loc) · 1.82 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
console.log(":)");
// Detail text toggle
Array.from(document.getElementsByTagName("details")).forEach(element => {
const defaultText = element.firstElementChild.textContent;
element.addEventListener("toggle", function () {
const isOpen = this.hasAttribute("open");
this.firstElementChild.textContent = isOpen ? "› Collapse" : defaultText;
});
});
// Collapsable sections
Array.from(document.getElementsByTagName("h2")).forEach(element => {
let content = element.nextElementSibling;
let text = element.textContent;
// Show the section if the h2 contains the show class
if (element.className.includes("show")) {
content.style.maxHeight = "max-content";
element.textContent = "[+] " + text;
} else {
element.textContent = "[–] " + text;
}
// Toggle collapsible
element.addEventListener("click", function () {
if (content.style.maxHeight) {
content.style.maxHeight = null;
this.textContent = "[–] " + text;
} else {
content.style.maxHeight = "max-content";
this.textContent = "[+] " + text;
}
});
});
// Pages
let projects = document.getElementById("projects");
let work = document.getElementById("work");
let projectsPage = document.getElementById("projects-page");
let workPage = document.getElementById("work-page");
let showProject = () => {
projects.style.fontWeight = "bold";
projectsPage.style.display = "block";
work.style.fontWeight = "normal";
workPage.style.display = "none";
};
let showWork = () => {
work.style.fontWeight = "bold";
workPage.style.display = "block";
projects.style.fontWeight = "normal";
projectsPage.style.display = "none";
}
showProject();
projects.addEventListener("click", showProject);
work.addEventListener("click", showWork);