-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
159 lines (157 loc) · 6.17 KB
/
main.js
File metadata and controls
159 lines (157 loc) · 6.17 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
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
(function () {
"use strict";
window.g = {
mobile: false,
mobileCSSLoaded: false
};
/**
* Fisher-Yates Shuffle. Code adapted from https://bost.ocks.org/mike/shuffle
* @param {Array} array - the array to in-place shuffle
* @returns {Array} - the shuffled array
*/
function shuffle (array) {
var counter = array.length;
while (counter > 0) {
var index = Math.floor(Math.random() * counter);
counter--;
var temp = array[counter];
array[counter] = array[index];
array[index] = temp;
}
return array;
}
var tiles = [];
var tileCounter = 0;
var night = false;
for (var i = 0; i < 60; i++) {
tiles[i] = i;
}
shuffle(tiles);
setInterval(function () {
if (document.getElementsByTagName("main")[0].scrollTop <= window.innerHeight) {
var aborted = false;
do {
if (tileCounter < 60) {
var tile = document.getElementById("innerTileWrapper").children[tiles[tileCounter]].classList;
tileCounter++;
if (night) {
if (tile.contains("hovera")) {
tile.toggle("hovera");
aborted = false;
} else if (tile.contains("hoverb")) {
tile.toggle("hoverb");
aborted = false;
} else if (tile.contains("hoverc")) {
tile.toggle("hoverc");
aborted = false;
} else if (tile.contains("hoverd")) {
tile.toggle("hoverd");
aborted = false;
} else {
aborted = true;
}
} else if (tile.contains("hovera") || tile.contains("hoverb") || tile.contains("hoverc") || tile.contains("hoverd")) {
aborted = true;
} else {
var flipClass = decodeURIComponent("hover%" + (61 + Math.floor(Math.random() * 4)));
tile.toggle(flipClass);
aborted = false;
}
} else {
tileCounter = 0;
shuffle(tiles);
night = !night;
aborted = false;
}
} while (aborted);
}
}, 2000);
(function () {
var elems = document.getElementsByClassName("fwrap");
for (var i = 0; i < elems.length; i++) {
elems[i].addEventListener("mouseenter", function (e) {
var tile = e.target.classList;
if (night) {
if (tile.contains("hovera")) {
tile.toggle("hovera");
} else if (tile.contains("hoverb")) {
tile.toggle("hoverb");
} else if (tile.contains("hoverc")) {
tile.toggle("hoverc");
} else if (tile.contains("hoverd")) {
tile.toggle("hoverd");
}
} else if (!tile.contains("hovera") && !tile.contains("hoverb") && !tile.contains("hoverc") && !tile.contains("hoverd")) {
tile.toggle(decodeURIComponent("hover%" + (61 + Math.floor(Math.random() * 4))));
}
});
}
})();
function resizeListener () { // eslint-disable-line require-jsdoc
if (window.innerHeight / window.innerWidth < 0.6) {
document.getElementById("outerTileWrapper").style.width = (Math.ceil(window.innerWidth / 100) * 100) + "px";
} else {
document.getElementById("outerTileWrapper").style.width = (Math.ceil(window.innerHeight / 60) * 100) + "px";
}
if (window.innerWidth < 713 && !window.g.mobile) {
window.g.mobile = true;
if (!window.g.mobileCSSLoaded) {
var css = document.createElement("link");
css.setAttribute("rel", "stylesheet");
css.setAttribute("type", "text/css");
css.setAttribute("href", "/mobile.css");
css.setAttribute("title", "mobile");
document.getElementsByTagName("head")[0].appendChild(css);
window.g.mobileCSSLoaded = true;
} else {
for (var i = 0; i < document.styleSheets.length; i++) {
if (document.styleSheets[i].title === "mobile") {
document.styleSheets[i].disabled = false;
}
}
}
} else if (window.innerWidth >= 713 && window.g.mobile) {
window.g.mobile = false;
for (var i = 0; i < document.styleSheets.length; i++) {
if (document.styleSheets[i].title === "mobile") {
document.styleSheets[i].disabled = true;
}
}
}
}
window.addEventListener("resize", resizeListener);
resizeListener();
var blinkState = true;
setInterval(function () {
var blinks = document.getElementsByClassName("cursor");
for (var i = 0; i < blinks.length; i++) {
blinks[i].style.visibility = blinkState ? "visible" : "hidden";
}
blinkState = !blinkState;
}, 1000);
})();
/**
* Scroll the document to the div#about
* @param {integer} iteration - Internal recursive parameter for keeping track of how many calls have been made
* @returns {undefined}
*/
function scrollToResume (iteration) {
"use strict";
if (typeof iteration === "undefined") {
iteration = 0;
}
if (iteration > 25) {
console.warn("Scroll taking too long - aborting");
return;
}
var elem = document.getElementsByTagName("main")[0];
var pos = document.getElementById("about").offsetTop;
var y = elem.scrollTop;
y += Math.round((pos - y) * 0.3);
if (Math.abs(y - pos) <= 2) {
elem.scrollTop = pos;
return;
}
elem.scrollTop = y;
setTimeout(scrollToResume, 40, ++iteration);
}