app.js 5.16 KB
Newer Older
1
'use strict'
2

3
/* eslint-disable no-new */
NGPixel's avatar
NGPixel committed
4

5
import $ from 'jquery'
6
import Vue from 'vue'
7
import VueResource from 'vue-resource'
8
import VueClipboards from 'vue-clipboards'
9
import VueLodash from 'vue-lodash'
10
import store from './store'
11
import io from 'socket-io-client'
12 13 14
import i18next from 'i18next'
import i18nextXHR from 'i18next-xhr-backend'
import VueI18Next from '@panter/vue-i18next'
15
import 'jquery-smooth-scroll'
16
import 'jquery-sticky'
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
// ====================================
// Load minimal lodash
// ====================================

import concat from 'lodash/concat'
import cloneDeep from 'lodash/cloneDeep'
import debounce from 'lodash/debounce'
import deburr from 'lodash/deburr'
import delay from 'lodash/delay'
import filter from 'lodash/filter'
import find from 'lodash/find'
import findKey from 'lodash/findKey'
import forEach from 'lodash/forEach'
import includes from 'lodash/includes'
import isEmpty from 'lodash/isEmpty'
import isNil from 'lodash/isNil'
import join from 'lodash/join'
import kebabCase from 'lodash/kebabCase'
import last from 'lodash/last'
import map from 'lodash/map'
import pullAt from 'lodash/pullAt'
import reject from 'lodash/reject'
import slice from 'lodash/slice'
import split from 'lodash/split'
import trim from 'lodash/trim'
import toUpper from 'lodash/toUpper'

45 46 47 48 49 50
// ====================================
// Load Helpers
// ====================================

import helpers from './helpers'

51 52 53 54
// ====================================
// Load Vue Components
// ====================================

55
import alertComponent from './components/alert.vue'
56 57
import anchorComponent from './components/anchor.vue'
import colorPickerComponent from './components/color-picker.vue'
58
import editorCodeblockComponent from './components/editor-codeblock.vue'
59
import editorVideoComponent from './components/editor-video.vue'
60
import loadingSpinnerComponent from './components/loading-spinner.vue'
61 62
import modalCreatePageComponent from './components/modal-create-page.vue'
import modalCreateUserComponent from './components/modal-create-user.vue'
63
import modalDeleteUserComponent from './components/modal-delete-user.vue'
64
import modalDiscardPageComponent from './components/modal-discard-page.vue'
65
import modalMovePageComponent from './components/modal-move-page.vue'
66
import pageLoaderComponent from './components/page-loader.vue'
67
import searchComponent from './components/search.vue'
68
import treeComponent from './components/tree.vue'
69 70 71

import adminProfileComponent from './pages/admin-profile.component.js'
import adminSettingsComponent from './pages/admin-settings.component.js'
72
import contentViewComponent from './pages/content-view.component.js'
73
import editorComponent from './components/editor.component.js'
74
import sourceViewComponent from './pages/source-view.component.js'
75

76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
// ====================================
// Build lodash object
// ====================================

const _ = {
  deburr,
  concat,
  cloneDeep,
  debounce,
  delay,
  filter,
  find,
  findKey,
  forEach,
  includes,
  isEmpty,
  isNil,
  join,
  kebabCase,
  last,
  map,
  pullAt,
  reject,
  slice,
  split,
  toUpper,
  trim
}

105
// ====================================
106
// Initialize Vue Modules
107 108
// ====================================

109
Vue.use(VueResource)
110
Vue.use(VueClipboards)
111
Vue.use(VueI18Next)
112
Vue.use(VueLodash, _)
113
Vue.use(helpers)
114 115 116 117 118 119 120 121 122 123 124

i18next
  .use(i18nextXHR)
  .init({
    backend: {
      loadPath: '/js/i18n/{{lng}}.json'
    },
    lng: siteLang,
    fallbackLng: siteLang
  })

125
$(() => {
126 127 128
  // ====================================
  // Notifications
  // ====================================
129

130
  $(window).bind('beforeunload', () => {
131
    store.dispatch('startLoading')
132 133
  })
  $(document).ajaxSend(() => {
134
    store.dispatch('startLoading')
135
  }).ajaxComplete(() => {
136
    store.dispatch('stopLoading')
137
  })
NGPixel's avatar
NGPixel committed
138

139 140 141
  // ====================================
  // Establish WebSocket connection
  // ====================================
142

143 144
  let socket = io(window.location.origin)
  window.socket = socket
145

146 147 148 149 150
  // ====================================
  // Bootstrap Vue
  // ====================================

  const i18n = new VueI18Next(i18next)
151
  window.wikijs = new Vue({
152
    mixins: [helpers],
153
    components: {
154
      alert: alertComponent,
155 156 157 158
      adminProfile: adminProfileComponent,
      adminSettings: adminSettingsComponent,
      anchor: anchorComponent,
      colorPicker: colorPickerComponent,
159
      contentView: contentViewComponent,
160
      editor: editorComponent,
161
      editorCodeblock: editorCodeblockComponent,
162
      editorVideo: editorVideoComponent,
163
      loadingSpinner: loadingSpinnerComponent,
164 165
      modalCreatePage: modalCreatePageComponent,
      modalCreateUser: modalCreateUserComponent,
166
      modalDeleteUser: modalDeleteUserComponent,
167
      modalDiscardPage: modalDiscardPageComponent,
168
      modalMovePage: modalMovePageComponent,
169
      pageLoader: pageLoaderComponent,
170
      search: searchComponent,
171
      sourceView: sourceViewComponent,
172
      tree: treeComponent
173
    },
174 175
    store,
    i18n,
176 177
    el: '#root',
    mounted() {
178
      $('a:not(.toc-anchor)').smoothScroll({ speed: 500, offset: -50 })
179 180 181
      $('#header').sticky({ topSpacing: 0 })
      $('.sidebar-pagecontents').sticky({ topSpacing: 15, bottomSpacing: 75 })
    }
182
  })
183
})