2
0

app.js 5.6 KB

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