-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrontend.js
92 lines (73 loc) · 3.04 KB
/
frontend.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
// APPEARANCE CONTROLS
const aMini = document.querySelector('#appearance-mini');
const aMenu = document.querySelector('#appearance-menu');
const aMenuTitle = document.querySelector('#appearance-menu-title');
const lightTheme = document.querySelector('#light-theme');
function showOptions () {
aMini.style.display = "none";
aMenu.style.display = "block";
lightTheme.focus();
}
function hideOptions () {
aMenu.style.display = "none";
aMini.style.display = "block";
aMini.focus();
}
// relevant eventListeners added at the bottom
const root = document.querySelector(':root');
function changeTheme (event) { // will be passed the event by the event listener
const l = '#261a28';
const d = '#f6efed';
const theme = event.currentTarget.getAttribute('id'); // theme = the id of whichever elem was clicked on
switch (theme) {
case "light-theme":
root.style.setProperty('--foreground-shade', l);
root.style.setProperty('--background-shade', d);
break;
case "dark-theme":
root.style.setProperty('--foreground-shade', d);
root.style.setProperty('--background-shade', l);
break;
case "contrast-theme":
root.style.setProperty('--foreground-shade', '#000');
root.style.setProperty('--background-shade', '#fff');
break;
}
}
function serif() {
root.style.fontFamily = "'Cormorant Garamond', Garamond, serif";
}
function sans() {
root.style.fontFamily = "Lato, sans-serif";
}
function normalSize() {
document.getElementById('main').style.fontSize = "1rem";
document.getElementById('main').style.lineHeight = "1.4em";
}
function largeSize() {
document.getElementById('main').style.fontSize = "1.5rem";
document.getElementById('main').style.lineHeight = "2em";
}
function showPopUpMenu() {
document.getElementById('main').style.filter = "blur(15px)";
document.getElementById('pop-up-appearance-menu').style.display = "block";
}
function hidePopUpMenu() {
document.getElementById('main').style.filter = "none";
document.getElementById('pop-up-appearance-menu').style.display = "none";
}
//SCROLL BUTTON
const scrollToTopButton = document.getElementById('scroll-to-top');
function scrollToTop () {
scroll(0,0);
}
// ADD EVENT LISTENERS
aMini.addEventListener('click', showOptions); // for heaven's sake don't add brackets it makes it fire on page load
aMenuTitle.addEventListener('click', hideOptions); // click also handles keyboard equivs, since these are focusable elems
lightTheme.addEventListener('click', changeTheme);
document.querySelector('#dark-theme').addEventListener('click', changeTheme);
document.querySelector('#contrast-theme').addEventListener('click', changeTheme);
document.querySelector('#serif-typeface').addEventListener('click', serif);
document.querySelector('#sans-typeface').addEventListener('click', sans);
document.querySelector('#standard-size').addEventListener('click', normalSize);
document.querySelector('#large-size').addEventListener('click', largeSize);