app.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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-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 loadingSpinnerComponent from './components/loading-spinner.vue'
  60. import modalCreatePageComponent from './components/modal-create-page.vue'
  61. import modalCreateUserComponent from './components/modal-create-user.vue'
  62. import modalDeleteUserComponent from './components/modal-delete-user.vue'
  63. import modalDiscardPageComponent from './components/modal-discard-page.vue'
  64. import modalMovePageComponent from './components/modal-move-page.vue'
  65. import pageLoaderComponent from './components/page-loader.vue'
  66. import searchComponent from './components/search.vue'
  67. import treeComponent from './components/tree.vue'
  68. import adminProfileComponent from './pages/admin-profile.component.js'
  69. import adminSettingsComponent from './pages/admin-settings.component.js'
  70. import contentViewComponent from './pages/content-view.component.js'
  71. import editorComponent from './components/editor.component.js'
  72. import sourceViewComponent from './pages/source-view.component.js'
  73. // ====================================
  74. // Build lodash object
  75. // ====================================
  76. const _ = {
  77. deburr,
  78. concat,
  79. cloneDeep,
  80. debounce,
  81. delay,
  82. filter,
  83. find,
  84. findKey,
  85. forEach,
  86. includes,
  87. isBoolean,
  88. isEmpty,
  89. isNil,
  90. join,
  91. kebabCase,
  92. last,
  93. map,
  94. nth,
  95. pullAt,
  96. reject,
  97. slice,
  98. split,
  99. startCase,
  100. toString,
  101. toUpper,
  102. trim
  103. }
  104. // ====================================
  105. // Initialize Vue Modules
  106. // ====================================
  107. Vue.use(VueResource)
  108. Vue.use(VueClipboards)
  109. Vue.use(VueI18Next)
  110. Vue.use(VueLodash, _)
  111. Vue.use(helpers)
  112. i18next
  113. .use(i18nextXHR)
  114. .init({
  115. backend: {
  116. loadPath: '/js/i18n/{{lng}}.json'
  117. },
  118. lng: siteLang,
  119. fallbackLng: siteLang
  120. })
  121. $(() => {
  122. // ====================================
  123. // Notifications
  124. // ====================================
  125. $(window).bind('beforeunload', () => {
  126. store.dispatch('startLoading')
  127. })
  128. $(document).ajaxSend(() => {
  129. store.dispatch('startLoading')
  130. }).ajaxComplete(() => {
  131. store.dispatch('stopLoading')
  132. })
  133. // ====================================
  134. // Establish WebSocket connection
  135. // ====================================
  136. let socket = io(window.location.origin)
  137. window.socket = socket
  138. // ====================================
  139. // Bootstrap Vue
  140. // ====================================
  141. const i18n = new VueI18Next(i18next)
  142. window.wikijs = new Vue({
  143. mixins: [helpers],
  144. components: {
  145. alert: alertComponent,
  146. adminProfile: adminProfileComponent,
  147. adminSettings: adminSettingsComponent,
  148. anchor: anchorComponent,
  149. colorPicker: colorPickerComponent,
  150. contentView: contentViewComponent,
  151. editor: editorComponent,
  152. editorCodeblock: editorCodeblockComponent,
  153. editorFile: editorFileComponent,
  154. editorVideo: editorVideoComponent,
  155. loadingSpinner: loadingSpinnerComponent,
  156. modalCreatePage: modalCreatePageComponent,
  157. modalCreateUser: modalCreateUserComponent,
  158. modalDeleteUser: modalDeleteUserComponent,
  159. modalDiscardPage: modalDiscardPageComponent,
  160. modalMovePage: modalMovePageComponent,
  161. pageLoader: pageLoaderComponent,
  162. search: searchComponent,
  163. sourceView: sourceViewComponent,
  164. tree: treeComponent
  165. },
  166. store,
  167. i18n,
  168. el: '#root',
  169. mounted() {
  170. $('a:not(.toc-anchor)').smoothScroll({ speed: 500, offset: -50 })
  171. $('#header').sticky({ topSpacing: 0 })
  172. $('.sidebar-pagecontents').sticky({ topSpacing: 15, bottomSpacing: 75 })
  173. }
  174. })
  175. })