app.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. 'use strict'
  2. /* global alertsData, siteLang */
  3. /* eslint-disable no-new */
  4. import $ from 'jquery'
  5. import _ from 'lodash'
  6. import Vue from 'vue'
  7. import Vuex from 'vuex'
  8. import io from 'socket.io-client'
  9. import i18next from 'i18next'
  10. import i18nextXHR from 'i18next-xhr-backend'
  11. import VueI18Next from '@panter/vue-i18next'
  12. import Alerts from './components/alerts.js'
  13. import 'jquery-smooth-scroll'
  14. import 'jquery-sticky'
  15. // ====================================
  16. // Load Vue Components
  17. // ====================================
  18. import anchorComponent from './components/anchor.vue'
  19. import colorPickerComponent from './components/color-picker.vue'
  20. import loadingSpinnerComponent from './components/loading-spinner.vue'
  21. import searchComponent from './components/search.vue'
  22. import adminProfileComponent from './pages/admin-profile.component.js'
  23. import adminSettingsComponent from './pages/admin-settings.component.js'
  24. // ====================================
  25. // Initialize i18next
  26. // ====================================
  27. Vue.use(VueI18Next)
  28. i18next
  29. .use(i18nextXHR)
  30. .init({
  31. backend: {
  32. loadPath: '/js/i18n/{{lng}}.json'
  33. },
  34. lng: siteLang,
  35. fallbackLng: siteLang
  36. })
  37. // ====================================
  38. // Initialize Vuex
  39. // ====================================
  40. Vue.use(Vuex)
  41. const store = new Vuex.Store({
  42. state: {
  43. loading: false
  44. },
  45. mutations: {
  46. startLoading: state => { state.loading = true },
  47. stopLoading: state => { state.loading = false }
  48. }
  49. })
  50. $(() => {
  51. // ====================================
  52. // Scroll
  53. // ====================================
  54. $('a').smoothScroll({
  55. speed: 500,
  56. offset: -50
  57. })
  58. $('#header').sticky({ topSpacing: 0 })
  59. $('.sidebar-pagecontents').sticky({ topSpacing: 15, bottomSpacing: 75 })
  60. // ====================================
  61. // Notifications
  62. // ====================================
  63. $(window).bind('beforeunload', () => {
  64. store.commit('startLoading')
  65. })
  66. $(document).ajaxSend(() => {
  67. store.commit('startLoading')
  68. }).ajaxComplete(() => {
  69. store.commit('stopLoading')
  70. })
  71. var alerts = {}
  72. /*var alerts = new Alerts()
  73. if (alertsData) {
  74. _.forEach(alertsData, (alertRow) => {
  75. alerts.push(alertRow)
  76. })
  77. }*/
  78. // ====================================
  79. // Establish WebSocket connection
  80. // ====================================
  81. let socket = io(window.location.origin)
  82. window.socket = socket
  83. // ====================================
  84. // Bootstrap Vue
  85. // ====================================
  86. const i18n = new VueI18Next(i18next)
  87. new Vue({
  88. components: {
  89. adminProfile: adminProfileComponent,
  90. adminSettings: adminSettingsComponent,
  91. anchor: anchorComponent,
  92. colorPicker: colorPickerComponent,
  93. loadingSpinner: loadingSpinnerComponent,
  94. search: searchComponent
  95. },
  96. store,
  97. i18n,
  98. el: '#root'
  99. })
  100. // ====================================
  101. // Pages logic
  102. // ====================================
  103. require('./pages/view.js')(alerts)
  104. require('./pages/all.js')(alerts, socket)
  105. require('./pages/create.js')(alerts, socket)
  106. require('./pages/edit.js')(alerts, socket)
  107. require('./pages/source.js')(alerts)
  108. require('./pages/history.js')(alerts)
  109. require('./pages/admin.js')(alerts)
  110. })