You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

183 lines
5.2 KiB

  1. 'use strict'
  2. /* eslint-disable no-new */
  3. import $ from 'jquery'
  4. import Vue from 'vue'
  5. import VueResource from 'vue-resource'
  6. import VueClipboards from 'vue-clipboards'
  7. import VueLodash from 'vue-lodash'
  8. import store from './store'
  9. import io from 'socket-io-client'
  10. import i18next from 'i18next'
  11. import i18nextXHR from 'i18next-xhr-backend'
  12. import VueI18Next from '@panter/vue-i18next'
  13. import 'jquery-smooth-scroll'
  14. import 'jquery-sticky'
  15. // ====================================
  16. // Load minimal lodash
  17. // ====================================
  18. import concat from 'lodash/concat'
  19. import cloneDeep from 'lodash/cloneDeep'
  20. import debounce from 'lodash/debounce'
  21. import deburr from 'lodash/deburr'
  22. import delay from 'lodash/delay'
  23. import filter from 'lodash/filter'
  24. import find from 'lodash/find'
  25. import findKey from 'lodash/findKey'
  26. import forEach from 'lodash/forEach'
  27. import includes from 'lodash/includes'
  28. import isEmpty from 'lodash/isEmpty'
  29. import isNil from 'lodash/isNil'
  30. import join from 'lodash/join'
  31. import kebabCase from 'lodash/kebabCase'
  32. import last from 'lodash/last'
  33. import map from 'lodash/map'
  34. import pullAt from 'lodash/pullAt'
  35. import reject from 'lodash/reject'
  36. import slice from 'lodash/slice'
  37. import split from 'lodash/split'
  38. import trim from 'lodash/trim'
  39. import toUpper from 'lodash/toUpper'
  40. // ====================================
  41. // Load Helpers
  42. // ====================================
  43. import helpers from './helpers'
  44. // ====================================
  45. // Load Vue Components
  46. // ====================================
  47. import alertComponent from './components/alert.vue'
  48. import anchorComponent from './components/anchor.vue'
  49. import colorPickerComponent from './components/color-picker.vue'
  50. import editorCodeblockComponent from './components/editor-codeblock.vue'
  51. import editorVideoComponent from './components/editor-video.vue'
  52. import loadingSpinnerComponent from './components/loading-spinner.vue'
  53. import modalCreatePageComponent from './components/modal-create-page.vue'
  54. import modalCreateUserComponent from './components/modal-create-user.vue'
  55. import modalDeleteUserComponent from './components/modal-delete-user.vue'
  56. import modalDiscardPageComponent from './components/modal-discard-page.vue'
  57. import modalMovePageComponent from './components/modal-move-page.vue'
  58. import pageLoaderComponent from './components/page-loader.vue'
  59. import searchComponent from './components/search.vue'
  60. import treeComponent from './components/tree.vue'
  61. import adminProfileComponent from './pages/admin-profile.component.js'
  62. import adminSettingsComponent from './pages/admin-settings.component.js'
  63. import contentViewComponent from './pages/content-view.component.js'
  64. import editorComponent from './components/editor.component.js'
  65. import sourceViewComponent from './pages/source-view.component.js'
  66. // ====================================
  67. // Build lodash object
  68. // ====================================
  69. const _ = {
  70. deburr,
  71. concat,
  72. cloneDeep,
  73. debounce,
  74. delay,
  75. filter,
  76. find,
  77. findKey,
  78. forEach,
  79. includes,
  80. isEmpty,
  81. isNil,
  82. join,
  83. kebabCase,
  84. last,
  85. map,
  86. pullAt,
  87. reject,
  88. slice,
  89. split,
  90. toUpper,
  91. trim
  92. }
  93. // ====================================
  94. // Initialize Vue Modules
  95. // ====================================
  96. Vue.use(VueResource)
  97. Vue.use(VueClipboards)
  98. Vue.use(VueI18Next)
  99. Vue.use(VueLodash, _)
  100. Vue.use(helpers)
  101. i18next
  102. .use(i18nextXHR)
  103. .init({
  104. backend: {
  105. loadPath: '/js/i18n/{{lng}}.json'
  106. },
  107. lng: siteLang,
  108. fallbackLng: siteLang
  109. })
  110. $(() => {
  111. // ====================================
  112. // Notifications
  113. // ====================================
  114. $(window).bind('beforeunload', () => {
  115. store.dispatch('startLoading')
  116. })
  117. $(document).ajaxSend(() => {
  118. store.dispatch('startLoading')
  119. }).ajaxComplete(() => {
  120. store.dispatch('stopLoading')
  121. })
  122. // ====================================
  123. // Establish WebSocket connection
  124. // ====================================
  125. let socket = io(window.location.origin)
  126. window.socket = socket
  127. // ====================================
  128. // Bootstrap Vue
  129. // ====================================
  130. const i18n = new VueI18Next(i18next)
  131. window.wikijs = new Vue({
  132. mixins: [helpers],
  133. components: {
  134. alert: alertComponent,
  135. adminProfile: adminProfileComponent,
  136. adminSettings: adminSettingsComponent,
  137. anchor: anchorComponent,
  138. colorPicker: colorPickerComponent,
  139. contentView: contentViewComponent,
  140. editor: editorComponent,
  141. editorCodeblock: editorCodeblockComponent,
  142. editorVideo: editorVideoComponent,
  143. loadingSpinner: loadingSpinnerComponent,
  144. modalCreatePage: modalCreatePageComponent,
  145. modalCreateUser: modalCreateUserComponent,
  146. modalDeleteUser: modalDeleteUserComponent,
  147. modalDiscardPage: modalDiscardPageComponent,
  148. modalMovePage: modalMovePageComponent,
  149. pageLoader: pageLoaderComponent,
  150. search: searchComponent,
  151. sourceView: sourceViewComponent,
  152. tree: treeComponent
  153. },
  154. store,
  155. i18n,
  156. el: '#root',
  157. mounted() {
  158. $('a:not(.toc-anchor)').smoothScroll({ speed: 500, offset: -50 })
  159. $('#header').sticky({ topSpacing: 0 })
  160. $('.sidebar-pagecontents').sticky({ topSpacing: 15, bottomSpacing: 75 })
  161. }
  162. })
  163. })