-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
195 lines (180 loc) · 6.22 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
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
window.addEventListener("load", () => {
const top = document.getElementById("top");
const left = document.getElementById("left");
const center = document.getElementById("center");
const right = document.getElementById("right");
const tabButtons = Array.from(document.querySelectorAll("#select > button"));
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 physicalProjects = ["soft networks", "handhold mouse", "eeg cloud", "ai loves horror", "text me smth nice"];
const analogProjects = ["tableware", "filmotography", "reveries"]; // "generative riso poster"
const titles = ["yosemite", "alaska", "eastcoast", "tableware", "reveries"];
function switchFilmView(e = {target: {title: ""}}) {
let switches = [1, 0, 0, 0, 0];
switch (e.target.title) {
case "tableware":
switches = [0, 0, 0, 1, 0];
break;
case "yosemite":
switches = [1, 0, 0, 0, 0];
break;
case "alaska":
switches = [0, 1, 0, 0, 0];
break;
case "east coast":
switches = [0, 0, 1, 0, 0];
break;
case "reveries":
switches = [0, 0, 0, 0, 1];
break;
default:
switches = [0, 0, 0, 0, 0];
break;
}
switches.forEach((on, index) => {
if (on) document.getElementById(titles[index]).style.display = "flex";
else document.getElementById(titles[index]).style.display = "none";
if (index < 3) 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";
previousElement = center; // since we got here from projects tab
}
// turn off previous, turn on current
if (previousElementSub.id.includes("filmotography")) switchFilmView();
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 === "filmotography") switchFilmView({target: {title: "yosemite"}});
if (currentElement.id === "tableware") switchFilmView({target: {title: "tableware"}});
if (currentElement.id === "reveries") switchFilmView({target: {title: "reveries"}});
}
function loadProjects(projects, label) {
const ptr = document.createElement('tr');
const th = document.createElement('th');
const th3 = document.createElement('h3');
th3.innerText = label;
th.appendChild(th3);
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 subelement = document.getElementById(selected);
location.hash = selected;
switchView(subelement, true);
}
}
function onSelect(e) {
const selected = e.target.innerText;
let elem;
switch (selected) {
case "projects":
elem = left;
break;
case "about":
elem = right;
break;
default:
elem = center;
break;
}
switchView(elem, false);
}
function oops() {
oopsies.onclick = null;
const wp = document.getElementById("wallpaper");
const temp = wp.style.content;
wp.style.content = "url('public/anna.png')";
switchView(center, false);
setTimeout(() => {
wp.style.content = temp;
oopsies.onclick = () => oops();
}, 350);
}
loadProjects(physicalProjects, "physical");
loadProjects(analogProjects, "analog");
loadProjects([], "digital");
tabButtons.forEach((elem) => {
elem.onclick = (e) => onSelect(e);
});
oopsies.onclick = oops;
radioButtons.forEach((button) => {
button.addEventListener("click", switchFilmView);
});
let dotIndex = 0;
const dotMax = 150;
document.body.addEventListener("mousemove", (e) => {
const dots = Array.from(document.getElementsByTagName("dot"));
let dot;
if (dots.length < dotMax) {
dot = document.createElement("dot");
dot.innerText = '.';
document.body.appendChild(dot);
} else {
dot = dots[dotIndex];
dotIndex++;
}
if (dotIndex >= dotMax) dotIndex = 0;
dot.style.left = `${e.x}px`;
dot.style.top = `${e.y}px`;
});
document.body.addEventListener("touchmove", (e) => {
if (getComputedStyle(center).display === "none") {
document.body.style.overflow = "visible";
return;
}
e.preventDefault();
document.body.style.overflow = "hidden";
const dots = Array.from(document.getElementsByTagName("dot"));
let dot;
if (dots.length < dotMax) {
dot = document.createElement("dot");
dot.innerText = '.';
document.body.appendChild(dot);
} else {
dot = dots[dotIndex];
dotIndex++;
}
if (dotIndex >= dotMax) dotIndex = 0;
dot.style.left = `${e.targetTouches[0].pageX}px`;
dot.style.top = `${e.targetTouches[0].pageY}px`;
document.body.appendChild(dot);
});
if (isSmallScreen) switchView(right);
if (location.hash) onSelectProject({target: {innerText: location.hash.split("#")[1]}});
});