Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
70 lines (58 loc) · 2.19 KB
/
Copy pathscript.js
File metadata and controls
70 lines (58 loc) · 2.19 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
// LIGHT & DARK THEME
const lightButton = document.getElementById('light');
const darkButton = document.getElementById('dark');
const themeElements = document.querySelectorAll('.light-theme');
const themes = ['light-theme', 'dark-theme'];
// Clear any theme currently applied
const clearTheme = () => {
themes.forEach(theme => {
themeElements.forEach(themeElements => {
if (themeElements.classList.contains(theme)) {
themeElements.classList.remove(theme);
}})
})}
// Applies new theme
const handleTheme = (theme) => {
clearTheme();
themeElements.forEach(themeElements => {
if (themeElements.classList.contains(theme)) {
return;
} else {
themeElements.classList.add(theme);
}
})}
lightButton.addEventListener('click', function() {handleTheme('light-theme')});
darkButton.addEventListener('click', function() {handleTheme('dark-theme')});
// ACCENT COLOURS
const blueButton = document.getElementById('blue');
const greenButton = document.getElementById('green');
const coralButton = document.getElementById('coral');
const purpleButton = document.getElementById('purple');
const clearButton = document.getElementById('clear');
const buttons = document.querySelectorAll('button');
// Array of available accent colours
const accentColours = ['blue', 'green', 'coral', 'purple'];
// Clears any accent colour currently applied
const clearAccent = () => {
accentColours.forEach(accentColour => {
buttons.forEach(buttons => {
if (buttons.classList.contains(accentColour)) {
buttons.classList.remove(accentColour);
}})
})
}
// Applies accent colour
const handleAccent = (colour) => {
clearAccent();
buttons.forEach(buttons => {
if (buttons.classList.contains(colour)) {
return;
} else {
buttons.classList.add(colour);
}
})}
blueButton.addEventListener('click', function() {handleAccent('blue')});
greenButton.addEventListener('click', function() {handleAccent('green')});
coralButton.addEventListener('click', function() {handleAccent('coral')});
purpleButton.addEventListener('click', function() {handleAccent('purple')});
clearButton.addEventListener('click', clearAccent);