-
Notifications
You must be signed in to change notification settings - Fork 8
/
start-app.js
63 lines (49 loc) · 1.75 KB
/
start-app.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
62
63
import $ from 'jquery'
import isMobile from '~/src/util/is-mobile'
import template from './app.stache'
import Lang from '~/src/mobile/util/lang'
import Logic from '~/src/mobile/util/logic'
import constants from '~/src/models/constants'
import PersistedState from '~/src/models/persisted-state'
import setMobileDesktopClass from '~/src/util/set-mobile-desktop-class'
import { analytics } from '~/src/util/analytics'
import route from 'can-route'
import '~/src/util/object-assign-polyfill'
export default function ({ interview, pState, mState, appState }) {
route.start()
pState = pState || new PersistedState()
pState.attr('setDataURL', mState.attr('setDataURL'))
pState.attr('autoSetDataURL', mState.attr('autoSetDataURL'))
const lang = new Lang(interview.attr('language'))
const answers = pState.attr('answers')
answers.lang = lang
answers.assign(interview.serialize().vars)
const incompleteKey = constants.vnInterviewIncompleteTF.toLowerCase()
answers.varSet(incompleteKey, {
name: incompleteKey,
type: constants.vtTF,
values: [null, true]
})
interview.attr('answers', answers)
const logic = new Logic({
interview: interview
})
pState.backup()
appState.bind('change', function (ev, attr, how, val) {
if (attr === 'page' && val) {
pState.attr('currentPage', val)
}
})
appState.interview = interview
setMobileDesktopClass(isMobile, $('body'))
appState.logic = logic
// set initial page route
appState.view = 'pages'
appState.page = interview.attr('firstPage')
// piwik: set author id for filtering/tracking
const authorId = interview.authorId || 0
analytics.initialize(authorId)
$('#viewer-app-container').append(template({
appState, pState, mState, interview, logic, lang, isMobile
}))
}