You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

159 lines
5.6 KiB

  1. 'use strict'
  2. /* global $, siteRoot */
  3. /* eslint-disable no-new */
  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 Helpers
  19. // ====================================
  20. import helpers from './helpers'
  21. import _ from './helpers/lodash'
  22. // ====================================
  23. // Load Vue Components
  24. // ====================================
  25. import alertComponent from './components/alert.vue'
  26. import anchorComponent from './components/anchor.vue'
  27. import colorPickerComponent from './components/color-picker.vue'
  28. import editorCodeblockComponent from './components/editor-codeblock.vue'
  29. import editorFileComponent from './components/editor-file.vue'
  30. import editorVideoComponent from './components/editor-video.vue'
  31. import historyComponent from './components/history.vue'
  32. import loadingSpinnerComponent from './components/loading-spinner.vue'
  33. import modalCreatePageComponent from './components/modal-create-page.vue'
  34. import modalCreateUserComponent from './components/modal-create-user.vue'
  35. import modalDeleteUserComponent from './components/modal-delete-user.vue'
  36. import modalDiscardPageComponent from './components/modal-discard-page.vue'
  37. import modalMovePageComponent from './components/modal-move-page.vue'
  38. import modalProfile2faComponent from './components/modal-profile-2fa.vue'
  39. import modalUpgradeSystemComponent from './components/modal-upgrade-system.vue'
  40. import pageLoaderComponent from './components/page-loader.vue'
  41. import searchComponent from './components/search.vue'
  42. import toggleComponent from './components/toggle.vue'
  43. import treeComponent from './components/tree.vue'
  44. import adminEditUserComponent from './pages/admin-edit-user.component.js'
  45. import adminProfileComponent from './pages/admin-profile.component.js'
  46. import adminSettingsComponent from './pages/admin-settings.component.js'
  47. import adminThemeComponent from './pages/admin-theme.component.js'
  48. import contentViewComponent from './pages/content-view.component.js'
  49. import editorComponent from './components/editor.component.js'
  50. import sourceViewComponent from './pages/source-view.component.js'
  51. // ====================================
  52. // Initialize Vue Modules
  53. // ====================================
  54. Vue.use(VueResource)
  55. Vue.use(VueClipboards)
  56. Vue.use(VueI18Next)
  57. Vue.use(VueLodash, _)
  58. Vue.use(helpers)
  59. // ====================================
  60. // Register Vue Components
  61. // ====================================
  62. Vue.component('alert', alertComponent)
  63. Vue.component('adminEditUser', adminEditUserComponent)
  64. Vue.component('adminProfile', adminProfileComponent)
  65. Vue.component('adminSettings', adminSettingsComponent)
  66. Vue.component('adminTheme', adminThemeComponent)
  67. Vue.component('anchor', anchorComponent)
  68. Vue.component('colorPicker', colorPickerComponent)
  69. Vue.component('contentView', contentViewComponent)
  70. Vue.component('editor', editorComponent)
  71. Vue.component('editorCodeblock', editorCodeblockComponent)
  72. Vue.component('editorFile', editorFileComponent)
  73. Vue.component('editorVideo', editorVideoComponent)
  74. Vue.component('history', historyComponent)
  75. Vue.component('loadingSpinner', loadingSpinnerComponent)
  76. Vue.component('modalCreatePage', modalCreatePageComponent)
  77. Vue.component('modalCreateUser', modalCreateUserComponent)
  78. Vue.component('modalDeleteUser', modalDeleteUserComponent)
  79. Vue.component('modalDiscardPage', modalDiscardPageComponent)
  80. Vue.component('modalMovePage', modalMovePageComponent)
  81. Vue.component('modalProfile2fa', modalProfile2faComponent)
  82. Vue.component('modalUpgradeSystem', modalUpgradeSystemComponent)
  83. Vue.component('pageLoader', pageLoaderComponent)
  84. Vue.component('search', searchComponent)
  85. Vue.component('sourceView', sourceViewComponent)
  86. Vue.component('toggle', toggleComponent)
  87. Vue.component('tree', treeComponent)
  88. // ====================================
  89. // Load Localization strings
  90. // ====================================
  91. i18next
  92. .use(i18nextXHR)
  93. .init({
  94. backend: {
  95. loadPath: siteRoot + '/js/i18n/{{lng}}.json'
  96. },
  97. lng: siteLang,
  98. fallbackLng: siteLang
  99. })
  100. $(() => {
  101. // ====================================
  102. // Notifications
  103. // ====================================
  104. $(window).bind('beforeunload', () => {
  105. store.dispatch('startLoading')
  106. })
  107. $(document).ajaxSend(() => {
  108. store.dispatch('startLoading')
  109. }).ajaxComplete(() => {
  110. store.dispatch('stopLoading')
  111. })
  112. // ====================================
  113. // Establish WebSocket connection
  114. // ====================================
  115. let socket = io(window.location.origin)
  116. window.socket = socket
  117. // ====================================
  118. // Bootstrap Vue
  119. // ====================================
  120. const i18n = new VueI18Next(i18next)
  121. window.wikijs = new Vue({
  122. mixins: [helpers],
  123. components: {},
  124. store,
  125. i18n,
  126. el: '#root',
  127. methods: {
  128. changeTheme(opts) {
  129. this.$el.className = `has-stickynav is-primary-${opts.primary} is-alternate-${opts.alt}`
  130. this.$refs.header.className = `nav is-${opts.primary}`
  131. this.$refs.footer.className = `footer is-${opts.footer}`
  132. }
  133. },
  134. mounted() {
  135. $('a:not(.toc-anchor)').smoothScroll({ speed: 500, offset: -50 })
  136. $('#header').sticky({ topSpacing: 0 })
  137. $('.sidebar-pagecontents').sticky({ topSpacing: 15, bottomSpacing: 75 })
  138. }
  139. })
  140. })