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.

153 lines
5.4 KiB

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