-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
61 lines (52 loc) · 1.89 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
let core = new Core()
core.register('back-button', BackButtonModule)
core.register('logging-gui', GuiLoggingModule)
core.register('router', RouteModule)
core.register('api', ApiModule)
core.register('sign', SignFormModule)
core.register('auth', AuthenticationModule)
core.register('feed', FeedModule)
core.register('post', PostModule)
core.register('post-feed', PostFeedModule)
core.startModules()
window.core = core
// Other stuff
function init() {
Array.from(document.querySelectorAll('.view-switch'))
.forEach(label => {
let radio = document.querySelector(`input[type=radio]#${label.getAttribute('for')}`)
if (radio) {
radio.addEventListener('change', (event) => {
switchView(radio.value)
})
}
})
core.subscribe('location-change', locationHash => {
let baseLocation = locationHash.split('/')[0]
switchView(baseLocation)
})
// Post init
location.hash = '#/sign-in'
}
init()
function switchView(viewName) {
// Switch view
Array.from(document.querySelectorAll('.view'))
.forEach(view => {
if (view.getAttribute('name').toLowerCase() === viewName.toLowerCase()) {
// view.style.display = 'initial'
view.removeAttribute('hidden')
} else {
view.setAttribute('hidden', true);
// view.style.display = 'none'
}
})
// Update radio button
Array.from(document.querySelectorAll('.view-switch'))
.forEach(label => {
let radio = document.querySelector(`input[type=radio]#${label.getAttribute('for')}`)
if (radio.value.toLowerCase() === viewName.toLowerCase() && !radio.getAttribute('checked')) {
radio.setAttribute('checked', true)
}
})
}