app.js 4.9 KB

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