-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
29 lines (23 loc) · 756 Bytes
/
index.js
File metadata and controls
29 lines (23 loc) · 756 Bytes
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
import cohorts from './cohorts.json'
import { Selectors, Info } from './components'
// add components to the DOM
const container = document.getElementById('cohorts')
const selectors = new Selectors(cohorts)
const info = new Info(cohorts)
selectors.appendTo(container)
info.appendTo(container)
// render all components
const render = () => {
const nextLocation = location.hash.substring(1);
const isValidLocation = !nextLocation || cohorts.some(({ hash }) => hash === nextLocation)
if (isValidLocation) {
selectors.setActive(nextLocation)
info.setActive(nextLocation)
} else {
location.hash = ''
}
}
// re-render whenever the URL hash changes
addEventListener('hashchange', render)
// render the components on page load
render()