-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
82 lines (71 loc) · 1.89 KB
/
main.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// 3rd party deps
import 'expose?$!expose?jQuery!jquery'
import 'bootstrap/dist/js/bootstrap'
import 'bootstrap/dist/css/bootstrap.min.css'
import 'bootstrap-social/bootstrap-social.css'
import 'font-awesome/css/font-awesome.css'
import $ from 'jquery'
import 'highlightjs/styles/default.css'
import Cookies from 'js-cookie'
// Vue deps
import Vue from 'vue'
import VueRouter from 'vue-router'
import VueI18n from 'vue-i18n'
import Vuex from 'vuex'
Vue.use(VueRouter)
Vue.use(Vuex)
Vue.use(VueI18n)
Vue.config.lang = 'fr'
Object.keys(locales).forEach(lang => {
Vue.locale(lang, locales[lang])
})
Vue.directive('focus', {
inserted: el => {
el.focus()
}
})
// App deps
import './css/style.css'
import locales from 'json!yaml!./locales.yml'
import Breadcrumb from './components/breadcrumb.vue'
import Account from './components/account.vue'
import Loading from './components/loading.vue'
import routes from './routes.js'
import helper from './helper'
import store from './store'
Vue.component('account', Account)
Vue.component('loading', Loading)
store.commit('setUser', helper.getUser())
const template = `<div class="container-fluid">
<breadcrumb></breadcrumb>
<div class="quizzy-view"><router-view></router-view></div>
</div>
`
$(() => {
const quizzyElt = '#quizzy'
const router = (function buildRouter() {
return new VueRouter({routes})
})()
router.beforeEach((to, from, next) => {
const initialPath = Cookies.get('initialPath')
if (initialPath && store.state.user) {
Cookies.remove('initialPath')
return next(initialPath)
}
if (!store.state.user && to.path !== '/') {
Cookies.set('initialPath', to.path)
return next('/')
}
next()
})
const quizId = helper.getContainerData('quizId')
if (quizId) {
store.commit('setQuizId', quizId)
}
new Vue({
template,
components: {Breadcrumb},
store,
router,
}).$mount(quizzyElt)
})