wikijs-fork/client/js/app.js

141 lines
3.7 KiB
JavaScript
Raw Normal View History

2017-02-09 01:52:37 +00:00
'use strict'
2017-09-10 05:41:22 +00:00
/* global siteConfig */
2017-03-27 02:07:40 +00:00
import CONSTANTS from './constants'
2017-05-21 03:21:16 +00:00
import Vue from 'vue'
2017-05-22 17:32:52 +00:00
import VueClipboards from 'vue-clipboards'
import VeeValidate from 'vee-validate'
2017-10-28 18:17:14 +00:00
import { ApolloClient } from 'apollo-client'
import { ApolloLink } from 'apollo-link'
import { createApolloFetch } from 'apollo-fetch'
import { BatchHttpLink } from 'apollo-link-batch-http'
2017-10-28 18:17:14 +00:00
import { InMemoryCache } from 'apollo-cache-inmemory'
2018-02-03 21:48:25 +00:00
import Hammer from 'hammerjs'
import store from './store'
2017-12-24 05:34:47 +00:00
// ====================================
// Load Modules
// ====================================
2018-02-03 21:48:25 +00:00
import boot from './modules/boot'
import localization from './modules/localization'
// ====================================
// Load Helpers
// ====================================
import helpers from './helpers'
// ====================================
// Initialize Global Vars
// ====================================
window.wiki = null
2018-02-03 21:48:25 +00:00
window.boot = boot
window.CONSTANTS = CONSTANTS
2018-02-03 21:48:25 +00:00
window.Hammer = Hammer
// ====================================
// Initialize Apollo Client (GraphQL)
// ====================================
const graphQLEndpoint = window.location.protocol + '//' + window.location.host + siteConfig.path + 'graphql'
const apolloFetch = createApolloFetch({
uri: graphQLEndpoint,
constructOptions: (requestOrRequests, options) => ({
...options,
method: 'POST',
body: JSON.stringify(requestOrRequests),
credentials: 'include'
})
})
window.graphQL = new ApolloClient({
link: ApolloLink.from([
new ApolloLink((operation, forward) => {
operation.setContext({
headers: {
'Content-Type': 'application/json'
}
})
return forward(operation)
}),
new BatchHttpLink({
fetch: apolloFetch
})
]),
2017-10-28 18:17:14 +00:00
cache: new InMemoryCache(),
connectToDevTools: (process.env.node_env === 'development')
})
2017-05-21 03:21:16 +00:00
// ====================================
// Initialize Vue Modules
2017-05-21 03:21:16 +00:00
// ====================================
2017-05-22 17:32:52 +00:00
Vue.use(VueClipboards)
Vue.use(localization.VueI18Next)
Vue.use(helpers)
Vue.use(VeeValidate, {
enableAutoClasses: true,
classNames: {
touched: 'is-touched', // the control has been blurred
untouched: 'is-untouched', // the control hasn't been blurred
valid: 'is-valid', // model is valid
invalid: 'is-invalid', // model is invalid
pristine: 'is-pristine', // control has not been interacted with
dirty: 'is-dirty' // control has been interacted with
}
})
2017-05-21 03:21:16 +00:00
2017-07-02 02:23:40 +00:00
// ====================================
// Register Vue Components
// ====================================
2018-02-03 21:48:25 +00:00
Vue.component('login', () => import(/* webpackMode: "eager" */ './components/login.vue'))
Vue.component('navigator', () => import(/* webpackMode: "eager" */ './components/navigator.vue'))
Vue.component('setup', () => import(/* webpackChunkName: "setup" */ './components/setup.vue'))
2018-02-03 21:48:25 +00:00
Vue.component('toggle', () => import(/* webpackMode: "eager" */ './components/toggle.vue'))
2017-07-02 02:23:40 +00:00
2018-02-03 21:48:25 +00:00
let bootstrap = () => {
// ====================================
// Notifications
// ====================================
2016-08-28 15:27:05 +00:00
2017-09-10 05:41:22 +00:00
window.addEventListener('beforeunload', () => {
store.dispatch('startLoading')
2017-02-09 01:52:37 +00:00
})
2017-05-21 03:21:16 +00:00
// ====================================
// Bootstrap Vue
// ====================================
const i18n = localization.init()
2017-09-10 05:41:22 +00:00
window.wiki = new Vue({
el: '#app',
2017-07-02 02:23:40 +00:00
components: {},
mixins: [helpers],
2017-05-21 03:21:16 +00:00
store,
2018-02-03 21:48:25 +00:00
i18n
2017-05-21 03:21:16 +00:00
})
2018-02-03 21:48:25 +00:00
// ----------------------------------
// Dispatch boot ready
// ----------------------------------
window.boot.notify('vue')
// ====================================
// Load Icons
// ====================================
2018-01-21 22:54:43 +00:00
import(/* webpackChunkName: "icons" */ '../svg/icons.svg').then(icons => {
document.body.insertAdjacentHTML('beforeend', icons)
})
2018-02-03 21:48:25 +00:00
}
window.boot.onDOMReady(bootstrap)