app.js 5.5 KB

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