forked from JoshuaNwaizu/quiz-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
66 lines (49 loc) · 2.1 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
const optionListItem = document.querySelector('.option__list')
function handleClick() {
return window.location.assign('./html-quiz.html')
}
optionListItem.addEventListener('click', handleClick)
/*=============== SHOW MENU ===============*/
/*
const showMenu = (toggleId) => {
toggle.addEventListener('click', () => {
// Add show-menu class to nav menu
toggle.classList.toggle('show-menu')
// Add show-icon to show and hide menu icon
})
}
showMenu('toggle-box')
-*/
/*=============== DARK LIGHT THEME ===============*/
const toggle = document.getElementById('toggle-box')
const darkTheme = 'dark-theme'
const iconTheme = 'toggle-icon'
// Previously selected topic (if user selected)
const selectedTheme = localStorage.getItem('selected-theme')
const selectedIcon = localStorage.getItem('selected-icon')
// We obtain the current theme that the interface has by validating the dark-theme class
const getCurrentTheme = () => document.body.classList.contains(darkTheme) ? 'dark' : 'light'
const getCurrentIcon = () => toggle.classList.contains(iconTheme) ? 'toggle-icon' : ''
// We validate if the user previously chose a topic
if (selectedTheme) {
// If the validation is fulfilled, we ask what the issue was to know if we activated or deactivated the dark
document.body.classList[selectedTheme === 'dark' ? 'add' : 'remove'](darkTheme)
toggle.classList[selectedIcon === 'toggle-icon' ? 'add' : 'remove'](iconTheme)
}
// Activate / deactivate the theme manually with the button
toggle.addEventListener('click', () => {
// Add or remove the dark / icon theme
document.body.classList.toggle(darkTheme)
toggle.classList.toggle(iconTheme)
// We save the theme and the current icon that the user chose
localStorage.setItem('selected-theme', getCurrentTheme())
localStorage.setItem('selected-icon', getCurrentIcon())
})
function displayAndHideText() {
const showText = document.querySelector('#show-text')
showText.style.display= 'block'
setTimeout(() => {
showText.style.display = 'none'
}, 5000);
}
window.onload = displayAndHideText