app.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. 'use strict'
  2. /* global siteLang */
  3. /* eslint-disable no-new */
  4. import $ from 'jquery'
  5. import Vue from 'vue'
  6. import VueResource from 'vue-resource'
  7. import VueClipboards from 'vue-clipboards'
  8. import VueLodash from 'vue-lodash'
  9. import store from './store'
  10. import io from 'socket-io-client'
  11. import i18next from 'i18next'
  12. import i18nextXHR from 'i18next-xhr-backend'
  13. import VueI18Next from '@panter/vue-i18next'
  14. import 'jquery-smooth-scroll'
  15. import 'jquery-sticky'
  16. // ====================================
  17. // Load minimal lodash
  18. // ====================================
  19. import concat from 'lodash/concat'
  20. import cloneDeep from 'lodash/cloneDeep'
  21. import debounce from 'lodash/debounce'
  22. import deburr from 'lodash/deburr'
  23. import delay from 'lodash/delay'
  24. import filter from 'lodash/filter'
  25. import find from 'lodash/find'
  26. import findKey from 'lodash/findKey'
  27. import forEach from 'lodash/forEach'
  28. import includes from 'lodash/includes'
  29. import isEmpty from 'lodash/isEmpty'
  30. import isNil from 'lodash/isNil'
  31. import join from 'lodash/join'
  32. import kebabCase from 'lodash/kebabCase'
  33. import last from 'lodash/last'
  34. import map from 'lodash/map'
  35. import pullAt from 'lodash/pullAt'
  36. import reject from 'lodash/reject'
  37. import slice from 'lodash/slice'
  38. import split from 'lodash/split'
  39. import trim from 'lodash/trim'
  40. import toUpper from 'lodash/toUpper'
  41. // ====================================
  42. // Load Helpers
  43. // ====================================
  44. import helpers from './helpers'
  45. // ====================================
  46. // Load Vue Components
  47. // ====================================
  48. import alertComponent from './components/alert.vue'
  49. import anchorComponent from './components/anchor.vue'
  50. import colorPickerComponent from './components/color-picker.vue'
  51. import editorCodeblockComponent from './components/editor-codeblock.vue'
  52. import loadingSpinnerComponent from './components/loading-spinner.vue'
  53. import modalCreatePageComponent from './components/modal-create-page.vue'
  54. import modalCreateUserComponent from './components/modal-create-user.vue'
  55. import modalDiscardPageComponent from './components/modal-discard-page.vue'
  56. import modalMovePageComponent from './components/modal-move-page.vue'
  57. import pageLoaderComponent from './components/page-loader.vue'
  58. import searchComponent from './components/search.vue'
  59. import treeComponent from './components/tree.vue'
  60. import adminProfileComponent from './pages/admin-profile.component.js'
  61. import adminSettingsComponent from './pages/admin-settings.component.js'
  62. import contentViewComponent from './pages/content-view.component.js'
  63. import editorComponent from './components/editor.component.js'
  64. import sourceViewComponent from './pages/source-view.component.js'
  65. // ====================================
  66. // Build lodash object
  67. // ====================================
  68. const _ = {
  69. deburr,
  70. concat,
  71. cloneDeep,
  72. debounce,
  73. delay,
  74. filter,
  75. find,
  76. findKey,
  77. forEach,
  78. includes,
  79. isEmpty,
  80. isNil,
  81. join,
  82. kebabCase,
  83. last,
  84. map,
  85. pullAt,
  86. reject,
  87. slice,
  88. split,
  89. toUpper,
  90. trim
  91. }
  92. // ====================================
  93. // Initialize Vue Modules
  94. // ====================================
  95. Vue.use(VueResource)
  96. Vue.use(VueClipboards)
  97. Vue.use(VueI18Next)
  98. Vue.use(VueLodash, _)
  99. Vue.use(helpers)
  100. i18next
  101. .use(i18nextXHR)
  102. .init({
  103. backend: {
  104. loadPath: '/js/i18n/{{lng}}.json'
  105. },
  106. lng: siteLang,
  107. fallbackLng: siteLang
  108. })
  109. $(() => {
  110. // ====================================
  111. // Notifications
  112. // ====================================
  113. $(window).bind('beforeunload', () => {
  114. store.dispatch('startLoading')
  115. })
  116. $(document).ajaxSend(() => {
  117. store.dispatch('startLoading')
  118. }).ajaxComplete(() => {
  119. store.dispatch('stopLoading')
  120. })
  121. // ====================================
  122. // Establish WebSocket connection
  123. // ====================================
  124. let socket = io(window.location.origin)
  125. window.socket = socket
  126. // ====================================
  127. // Bootstrap Vue
  128. // ====================================
  129. const i18n = new VueI18Next(i18next)
  130. new Vue({
  131. mixins: [helpers],
  132. components: {
  133. alert: alertComponent,
  134. adminProfile: adminProfileComponent,
  135. adminSettings: adminSettingsComponent,
  136. anchor: anchorComponent,
  137. colorPicker: colorPickerComponent,
  138. contentView: contentViewComponent,
  139. editor: editorComponent,
  140. editorCodeblock: editorCodeblockComponent,
  141. loadingSpinner: loadingSpinnerComponent,
  142. modalCreatePage: modalCreatePageComponent,
  143. modalCreateUser: modalCreateUserComponent,
  144. modalDiscardPage: modalDiscardPageComponent,
  145. modalMovePage: modalMovePageComponent,
  146. pageLoader: pageLoaderComponent,
  147. search: searchComponent,
  148. sourceView: sourceViewComponent,
  149. tree: treeComponent
  150. },
  151. store,
  152. i18n,
  153. el: '#root',
  154. mounted() {
  155. $('a:not(.toc-anchor)').smoothScroll({ speed: 500, offset: -50 })
  156. $('#header').sticky({ topSpacing: 0 })
  157. $('.sidebar-pagecontents').sticky({ topSpacing: 15, bottomSpacing: 75 })
  158. }
  159. })
  160. })