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.

205 lines
6.1 KiB

  1. 'use strict'
  2. /* global $, siteRoot */
  3. /* eslint-disable no-new */
  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-contextmenu'
  14. import 'jquery-simple-upload'
  15. import 'jquery-smooth-scroll'
  16. import 'jquery-sticky'
  17. // ====================================
  18. // Load minimal lodash
  19. // ====================================
  20. import cloneDeep from 'lodash/cloneDeep'
  21. import concat from 'lodash/concat'
  22. import debounce from 'lodash/debounce'
  23. import deburr from 'lodash/deburr'
  24. import delay from 'lodash/delay'
  25. import filter from 'lodash/filter'
  26. import find from 'lodash/find'
  27. import findKey from 'lodash/findKey'
  28. import forEach from 'lodash/forEach'
  29. import includes from 'lodash/includes'
  30. import isBoolean from 'lodash/isBoolean'
  31. import isEmpty from 'lodash/isEmpty'
  32. import isNil from 'lodash/isNil'
  33. import join from 'lodash/join'
  34. import kebabCase from 'lodash/kebabCase'
  35. import last from 'lodash/last'
  36. import map from 'lodash/map'
  37. import nth from 'lodash/nth'
  38. import pullAt from 'lodash/pullAt'
  39. import reject from 'lodash/reject'
  40. import slice from 'lodash/slice'
  41. import split from 'lodash/split'
  42. import startCase from 'lodash/startCase'
  43. import toString from 'lodash/toString'
  44. import toUpper from 'lodash/toUpper'
  45. import trim from 'lodash/trim'
  46. // ====================================
  47. // Load Helpers
  48. // ====================================
  49. import helpers from './helpers'
  50. // ====================================
  51. // Load Vue Components
  52. // ====================================
  53. import alertComponent from './components/alert.vue'
  54. import anchorComponent from './components/anchor.vue'
  55. import colorPickerComponent from './components/color-picker.vue'
  56. import editorCodeblockComponent from './components/editor-codeblock.vue'
  57. import editorFileComponent from './components/editor-file.vue'
  58. import editorVideoComponent from './components/editor-video.vue'
  59. import historyComponent from './components/history.vue'
  60. import loadingSpinnerComponent from './components/loading-spinner.vue'
  61. import modalCreatePageComponent from './components/modal-create-page.vue'
  62. 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 modalProfile2faComponent from './components/modal-profile-2fa.vue'
  67. import modalUpgradeSystemComponent from './components/modal-upgrade-system.vue'
  68. import pageLoaderComponent from './components/page-loader.vue'
  69. import searchComponent from './components/search.vue'
  70. import toggleComponent from './components/toggle.vue'
  71. import treeComponent from './components/tree.vue'
  72. import adminEditUserComponent from './pages/admin-edit-user.component.js'
  73. import adminProfileComponent from './pages/admin-profile.component.js'
  74. import adminSettingsComponent from './pages/admin-settings.component.js'
  75. import contentViewComponent from './pages/content-view.component.js'
  76. import editorComponent from './components/editor.component.js'
  77. import sourceViewComponent from './pages/source-view.component.js'
  78. // ====================================
  79. // Build lodash object
  80. // ====================================
  81. const _ = {
  82. deburr,
  83. concat,
  84. cloneDeep,
  85. debounce,
  86. delay,
  87. filter,
  88. find,
  89. findKey,
  90. forEach,
  91. includes,
  92. isBoolean,
  93. isEmpty,
  94. isNil,
  95. join,
  96. kebabCase,
  97. last,
  98. map,
  99. nth,
  100. pullAt,
  101. reject,
  102. slice,
  103. split,
  104. startCase,
  105. toString,
  106. toUpper,
  107. trim
  108. }
  109. // ====================================
  110. // Initialize Vue Modules
  111. // ====================================
  112. Vue.use(VueResource)
  113. Vue.use(VueClipboards)
  114. Vue.use(VueI18Next)
  115. Vue.use(VueLodash, _)
  116. Vue.use(helpers)
  117. i18next
  118. .use(i18nextXHR)
  119. .init({
  120. backend: {
  121. loadPath: siteRoot + '/js/i18n/{{lng}}.json'
  122. },
  123. lng: siteLang,
  124. 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. })
  138. // ====================================
  139. // Establish WebSocket connection
  140. // ====================================
  141. let socket = io(window.location.origin)
  142. window.socket = socket
  143. // ====================================
  144. // Bootstrap Vue
  145. // ====================================
  146. const i18n = new VueI18Next(i18next)
  147. window.wikijs = new Vue({
  148. mixins: [helpers],
  149. components: {
  150. alert: alertComponent,
  151. adminEditUser: adminEditUserComponent,
  152. adminProfile: adminProfileComponent,
  153. adminSettings: adminSettingsComponent,
  154. anchor: anchorComponent,
  155. colorPicker: colorPickerComponent,
  156. contentView: contentViewComponent,
  157. editor: editorComponent,
  158. editorCodeblock: editorCodeblockComponent,
  159. editorFile: editorFileComponent,
  160. editorVideo: editorVideoComponent,
  161. history: historyComponent,
  162. loadingSpinner: loadingSpinnerComponent,
  163. modalCreatePage: modalCreatePageComponent,
  164. modalCreateUser: modalCreateUserComponent,
  165. modalDeleteUser: modalDeleteUserComponent,
  166. modalDiscardPage: modalDiscardPageComponent,
  167. modalMovePage: modalMovePageComponent,
  168. modalProfile2fa: modalProfile2faComponent,
  169. modalUpgradeSystem: modalUpgradeSystemComponent,
  170. pageLoader: pageLoaderComponent,
  171. search: searchComponent,
  172. sourceView: sourceViewComponent,
  173. toggle: toggleComponent,
  174. tree: treeComponent
  175. },
  176. store,
  177. i18n,
  178. el: '#root',
  179. mounted() {
  180. $('a:not(.toc-anchor)').smoothScroll({ speed: 500, offset: -50 })
  181. $('#header').sticky({ topSpacing: 0 })
  182. $('.sidebar-pagecontents').sticky({ topSpacing: 15, bottomSpacing: 75 })
  183. }
  184. })
  185. })