aboutsummaryrefslogtreecommitdiff
path: root/public/javascripts/main.js
blob: de29a5db62327221252700eb2d1652834a0c4cb4 (plain)
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
const frontpage = require('./frontpage')
const search = require('./search')
const schedule = require('./schedule')
const weekSelector = require('./weekSelector')
const favorite = require('./favorite')

const state = {}

window.state = state
window.require = require

frontpage.show()
weekSelector.updateCurrentWeek()

if (favorite.get() != null) {
  state.selectedItem = favorite.get()
  favorite.update(state.selectedItem)
  schedule.viewItem(weekSelector.getSelectedWeek(), state.selectedItem)
} else {
  search.focus()
}

search.on('search', function (selectedItem) {
  state.selectedItem = selectedItem
  favorite.update(state.selectedItem)
  schedule.viewItem(weekSelector.getSelectedWeek(), state.selectedItem)
})

weekSelector.on('weekChanged', function (newWeek) {
  schedule.viewItem(newWeek, state.selectedItem)
})

favorite.on('click', function () {
  favorite.toggle(state.selectedItem)
})

window.weekSelector = weekSelector

document.body.style.opacity = 1