-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
141 lines (131 loc) · 4.49 KB
/
index.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
138
139
140
141
window.addEventListener("load", () => {
const top = document.getElementById("top");
const left = document.getElementById("left");
const center = document.getElementById("center");
const right = document.getElementById("right");
const select = document.getElementById("select");
const table = document.getElementById("projects-table");
const greeting = document.getElementById("greeting");
const oopsies = document.getElementById("oops");
const radioButtons = Array.from(document.getElementsByClassName("film-button"));
const isSmallScreen = getComputedStyle(top).display != "none";
let previousElement = center;
let previousElementSub = greeting;
const codeProjects = ["ai loves horror", "text me smth nice", "baby killer", "spotify recently added"];
const printProjects = ["filmotography", "generative riso poster"];
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min); // The maximum is exclusive and the minimum is inclusive
}
function switchFilmView(e = {target:{title:""}}) {
let switches = [1,0,0];
const titles = ["yosemite", "alaska", "eastcoast"];
switch (e.target.title) {
case "alaska":
switches = [0,1,0];
break;
case "east coast":
switches = [0,0,1];
break;
default:
switches = [1,0,0]; // yosemite by default
break;
}
switches.forEach((on, index) => {
if (on) document.getElementById(titles[index]).style.display = "flex";
else document.getElementById(titles[index]).style.display = "none";
radioButtons[index].selected = on == 1;
})
}
function switchView(currentElement, isSubView = false) {
if (isSubView) { // project view
if (isSmallScreen) {
left.style.display = "none";
right.style.display = "none";
center.style.display = "block";
select.value = "center";
previousElement = center; // since we got here from projects tab
}
// turn off previous, turn on current
previousElementSub.style.display = "none";
currentElement.style.display = "block";
previousElementSub = currentElement;
} else { // all other tabs
if (isSmallScreen) {
previousElement.style.display = "none";
currentElement.style.display = "block";
previousElement = currentElement;
}
previousElementSub.style.display = "none";
previousElement.style.display = "none";
currentElement.style.display = "block";
previousElement = currentElement;
}
greeting.style.display = currentElement == center ? "flex" : "none";
if (currentElement.id.includes("filmotography")) switchFilmView();
// console.log({currentElement},{previousElementSub});
}
function loadProjects(projects, label) {
const ptr = document.createElement('tr');
const th = document.createElement('td');
th.innerText = label;
ptr.appendChild(th);
table.appendChild(ptr);
projects.forEach((p) => {
const tr = document.createElement('tr');
const td = document.createElement('td');
const a = document.createElement('a');
a.href = "javascript:void(0);";
a.onclick = onSelectProject;
a.innerText = p;
td.appendChild(a);
tr.appendChild(td);
table.appendChild(tr);
})
}
function onSelectProject(e) {
const selected = e.target.innerText.split(" ")[0];
if (document.getElementById(selected)) {
let subelem = document.getElementById(selected);
switchView(subelem, true);
}
}
function onSelect(e) {
const selected = e.target.value;
let elem;
switch (selected) {
case "projects":
elem = left;
break;
case "about":
elem = right;
break;
default:
elem = center;
break;
}
switchView(elem, false, elem == center);
}
function oops(ev) {
oopsies.onclick = null;
const wp = document.getElementById("wallpaper");
const temp = wp.src;
wp.src = "public/anna.jpg";
switchView(center, false);
setTimeout(() => {
wp.src= temp;
oopsies.onclick = (ev) => oops(ev);
}, 350);
}
loadProjects(codeProjects, "code");
loadProjects(printProjects, "print");
select.onchange = (e) => onSelect(e);
oopsies.onclick = (ev) => oops(ev);
document.getElementById("home").onclick = () => {
switchView(center, false);
};
radioButtons.forEach((button) => {
button.addEventListener("click", switchFilmView);
});
});