require('./featureDetect').check() 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.hasSelectedItem()) { state.selectedItem = url.getSelectedItem() favorite.update(state.selectedItem) analytics.send.search(state.selectedItem) schedule.viewItem(weekSelector.getSelectedWeek(), state.selectedItem) } else if (favorite.get() != null) { state.selectedItem = favorite.get() favorite.update(state.selectedItem) url.update(state.selectedItem) analytics.send.search(state.selectedItem, true) schedule.viewItem(weekSelector.getSelectedWeek(), state.selectedItem) } else { search.focus() } search.on('search', function (selectedItem) { state.selectedItem = selectedItem favorite.update(state.selectedItem) url.update(state.selectedItem) analytics.send.search(state.selectedItem) schedule.viewItem(weekSelector.getSelectedWeek(), state.selectedItem) }) weekSelector.on('weekChanged', function (newWeek) { analytics.send.search(state.selectedItem) schedule.viewItem(newWeek, state.selectedItem) }) favorite.on('click', function () { favorite.toggle(state.selectedItem) }) url.on('update', function (selectedItem) { state.selectedItem = selectedItem favorite.update(state.selectedItem) schedule.viewItem(weekSelector.getSelectedWeek(), state.selectedItem) }) document.body.style.opacity = 1