app.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. 'use strict'
  2. /* global siteConfig */
  3. import CONSTANTS from './constants'
  4. import Vue from 'vue'
  5. import VueRouter from 'vue-router'
  6. import VueClipboards from 'vue-clipboards'
  7. import VueSimpleBreakpoints from 'vue-simple-breakpoints'
  8. import VeeValidate from 'vee-validate'
  9. import { ApolloClient } from 'apollo-client'
  10. import { ApolloLink } from 'apollo-link'
  11. import { createApolloFetch } from 'apollo-fetch'
  12. import { BatchHttpLink } from 'apollo-link-batch-http'
  13. import { InMemoryCache } from 'apollo-cache-inmemory'
  14. import Vuetify from 'vuetify'
  15. import Velocity from 'velocity-animate'
  16. import Hammer from 'hammerjs'
  17. import store from './store'
  18. // ====================================
  19. // Load Modules
  20. // ====================================
  21. import boot from './modules/boot'
  22. import localization from './modules/localization'
  23. // ====================================
  24. // Load Helpers
  25. // ====================================
  26. import helpers from './helpers'
  27. // ====================================
  28. // Initialize Global Vars
  29. // ====================================
  30. window.wiki = null
  31. window.boot = boot
  32. window.CONSTANTS = CONSTANTS
  33. window.Hammer = Hammer
  34. // ====================================
  35. // Initialize Apollo Client (GraphQL)
  36. // ====================================
  37. const graphQLEndpoint = window.location.protocol + '//' + window.location.host + siteConfig.path + 'graphql'
  38. const apolloFetch = createApolloFetch({
  39. uri: graphQLEndpoint,
  40. constructOptions: (requestOrRequests, options) => ({
  41. ...options,
  42. method: 'POST',
  43. body: JSON.stringify(requestOrRequests),
  44. credentials: 'include'
  45. })
  46. })
  47. window.graphQL = new ApolloClient({
  48. link: ApolloLink.from([
  49. new ApolloLink((operation, forward) => {
  50. operation.setContext({
  51. headers: {
  52. 'Content-Type': 'application/json'
  53. }
  54. })
  55. return forward(operation)
  56. }),
  57. new BatchHttpLink({
  58. fetch: apolloFetch
  59. })
  60. ]),
  61. cache: new InMemoryCache(),
  62. connectToDevTools: (process.env.node_env === 'development')
  63. })
  64. // ====================================
  65. // Initialize Vue Modules
  66. // ====================================
  67. Vue.use(VueRouter)
  68. Vue.use(VueClipboards)
  69. Vue.use(VueSimpleBreakpoints)
  70. Vue.use(localization.VueI18Next)
  71. Vue.use(helpers)
  72. Vue.use(VeeValidate, {
  73. enableAutoClasses: true,
  74. classNames: {
  75. touched: 'is-touched', // the control has been blurred
  76. untouched: 'is-untouched', // the control hasn't been blurred
  77. valid: 'is-valid', // model is valid
  78. invalid: 'is-invalid', // model is invalid
  79. pristine: 'is-pristine', // control has not been interacted with
  80. dirty: 'is-dirty' // control has been interacted with
  81. }
  82. })
  83. Vue.use(Vuetify)
  84. Vue.prototype.Velocity = Velocity
  85. // ====================================
  86. // Register Vue Components
  87. // ====================================
  88. Vue.component('admin', () => import(/* webpackChunkName: "admin" */ './components/admin.vue'))
  89. Vue.component('editor', () => import(/* webpackChunkName: "editor" */ './components/editor.vue'))
  90. Vue.component('login', () => import(/* webpackMode: "eager" */ './components/login.vue'))
  91. Vue.component('nav-header', () => import(/* webpackMode: "eager" */ './components/nav-header.vue'))
  92. Vue.component('navigator', () => import(/* webpackMode: "eager" */ './components/navigator.vue'))
  93. Vue.component('setup', () => import(/* webpackChunkName: "setup" */ './components/setup.vue'))
  94. Vue.component('toggle', () => import(/* webpackMode: "eager" */ './components/toggle.vue'))
  95. let bootstrap = () => {
  96. // ====================================
  97. // Notifications
  98. // ====================================
  99. window.addEventListener('beforeunload', () => {
  100. store.dispatch('startLoading')
  101. })
  102. // ====================================
  103. // Bootstrap Vue
  104. // ====================================
  105. const i18n = localization.init()
  106. window.wiki = new Vue({
  107. el: '#app',
  108. components: {},
  109. mixins: [helpers],
  110. store,
  111. i18n
  112. })
  113. // ----------------------------------
  114. // Dispatch boot ready
  115. // ----------------------------------
  116. window.boot.notify('vue')
  117. // ====================================
  118. // Load Icons
  119. // ====================================
  120. import(/* webpackChunkName: "icons" */ './svg/icons.svg').then(icons => {
  121. document.body.insertAdjacentHTML('beforeend', icons)
  122. })
  123. }
  124. window.boot.onDOMReady(bootstrap)