aboutsummaryrefslogtreecommitdiff
path: root/public/javascripts/main.js
blob: 5d0ef9cffa718b4af9162baedc620e0c96aceb73 (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
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
71
72
require('./featureDetect').check()
require('./zoom')

const frontpage = require('./frontpage')
const search = require('./search')
const schedule = require('./schedule')
const weekSelector = require('./weekSelector')
const favorite = require('./favorite')
const scrollSnap = require('./scrollSnap')
const analytics = require('./analytics')
const url = require('./url')

const state = {}

window.state = state
window.require = require

frontpage.show()
weekSelector.updateCurrentWeek()
scrollSnap.startListening()

if (url.hasSelectedUser()) {
  state.selectedUser = url.getSelectedUser()

  favorite.update(state.selectedUser)
  url.update(state.selectedUser)
  analytics.send.search(state.selectedUser)

  schedule.viewItem(weekSelector.getSelectedWeek(), state.selectedUser)
} else if (favorite.get() != null) {
  state.selectedUser = favorite.get()

  favorite.update(state.selectedUser)
  url.push(state.selectedUser, false)
  url.update(state.selectedUser)
  analytics.send.search(state.selectedUser, true)

  schedule.viewItem(weekSelector.getSelectedWeek(), state.selectedUser)
} else {
  search.focus()
}

search.on('search', function (selectedUser) {
  state.selectedUser = selectedUser

  favorite.update(state.selectedUser)
  url.push(state.selectedUser)
  url.update(state.selectedUser)
  analytics.send.search(state.selectedUser)

  schedule.viewItem(weekSelector.getSelectedWeek(), state.selectedUser)
})

url.on('update', function (selectedUser) {
  state.selectedUser = selectedUser

  favorite.update(state.selectedUser)
  url.update(state.selectedUser)

  schedule.viewItem(weekSelector.getSelectedWeek(), state.selectedUser)
})

weekSelector.on('weekChanged', function (newWeek) {
  analytics.send.search(state.selectedUser)
  schedule.viewItem(newWeek, state.selectedUser)
})

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

document.body.style.opacity = 1