-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
64 lines (50 loc) · 1.77 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
(function (w, d) {
console.log("loading index.js");
// // onLoad
// var onLoad = function(loadFn) {
// if (d.readyState === "complete") {
// loadFn();
// return;
// }
// // otherwise add a listener
// d.addEventListener("DOMContentLoaded", loadFn);
// };
// returns if some v is a space or a letter
const spaceOrLetter = (v) => (v === " ") ? "space" : "letter";
// convert an item into a div
const mkDivFn = (setClass) => {
// console.log("mkDivFn");
// function that will create a div
const wrapper = (v, i) => {
// console.log("mkDivFn::wrapper(", v, ", ", i, ")");
var div = d.createElement("div");
// set properties/attributes
div.id = (i + 1).toString();
div.className = setClass(v);
div.setAttribute("unselectable", "on");
div.textContent = v;
// return
return div;
};
// return the wrapping function
return wrapper;
}
const textToArray = (text) => text.split("");
const textToDivs = (text) => textToArray(text).map(mkDivFn(spaceOrLetter));
const loader = () => {
console.log("index::loader");
// get the header text content and re-write each to be a div
var header = d.qs("h1#header");
var node = header.removeChild(header.firstChild);
// reset header to be our new html
textToDivs(node.textContent).forEach((c) => header.appendChild(c))
// set onclick even on the header
header.onclick = Anim.pickAnimation(header, "div.letter");
// forever 3 second jump animation interval
setInterval(Anim.jumpChildren, 3000, header, "div.letter");
// // cycle colours forever
// setInterval(Colour.cycleChildren, 3000, header, "div.letter");
};
// set onload
w.onload = loader
})(window, document);