app.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 VueResource from 'vue-resource'
  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 Alerts from './components/alerts.js'
  14. import 'jquery-smooth-scroll'
  15. import 'jquery-sticky'
  16. // ====================================
  17. // Load Vue Components
  18. // ====================================
  19. import alertComponent from './components/alert.vue'
  20. import anchorComponent from './components/anchor.vue'
  21. import colorPickerComponent from './components/color-picker.vue'
  22. import loadingSpinnerComponent from './components/loading-spinner.vue'
  23. import searchComponent from './components/search.vue'
  24. import adminUsersCreateComponent from './modals/admin-users-create.vue'
  25. import adminProfileComponent from './pages/admin-profile.component.js'
  26. import adminSettingsComponent from './pages/admin-settings.component.js'
  27. // ====================================
  28. // Initialize Vue Modules
  29. // ====================================
  30. Vue.use(VueResource)
  31. Vue.use(VueI18Next)
  32. i18next
  33. .use(i18nextXHR)
  34. .init({
  35. backend: {
  36. loadPath: '/js/i18n/{{lng}}.json'
  37. },
  38. lng: siteLang,
  39. fallbackLng: siteLang
  40. })
  41. $(() => {
  42. // ====================================
  43. // Notifications
  44. // ====================================
  45. $(window).bind('beforeunload', () => {
  46. store.dispatch('startLoading')
  47. })
  48. $(document).ajaxSend(() => {
  49. store.dispatch('startLoading')
  50. }).ajaxComplete(() => {
  51. store.dispatch('stopLoading')
  52. })
  53. var alerts = {}
  54. /*var alerts = new Alerts()
  55. if (alertsData) {
  56. _.forEach(alertsData, (alertRow) => {
  57. alerts.push(alertRow)
  58. })
  59. }*/
  60. // ====================================
  61. // Establish WebSocket connection
  62. // ====================================
  63. let socket = io(window.location.origin)
  64. window.socket = socket
  65. // ====================================
  66. // Bootstrap Vue
  67. // ====================================
  68. const i18n = new VueI18Next(i18next)
  69. new Vue({
  70. components: {
  71. alert: alertComponent,
  72. adminProfile: adminProfileComponent,
  73. adminSettings: adminSettingsComponent,
  74. adminUsersCreate: adminUsersCreateComponent,
  75. anchor: anchorComponent,
  76. colorPicker: colorPickerComponent,
  77. loadingSpinner: loadingSpinnerComponent,
  78. search: searchComponent
  79. },
  80. directives: {
  81. // sticky: VueSticky
  82. },
  83. store,
  84. i18n,
  85. el: '#root',
  86. mounted() {
  87. $('a').smoothScroll({
  88. speed: 500,
  89. offset: -50
  90. })
  91. $('#header').sticky({ topSpacing: 0 })
  92. $('.sidebar-pagecontents').sticky({ topSpacing: 15, bottomSpacing: 75 })
  93. // ====================================
  94. // Pages logic
  95. // ====================================
  96. require('./pages/view.js')(alerts)
  97. require('./pages/all.js')(alerts, socket)
  98. require('./pages/create.js')(alerts, socket)
  99. require('./pages/edit.js')(alerts, socket)
  100. require('./pages/source.js')(alerts)
  101. require('./pages/history.js')(alerts)
  102. require('./pages/admin.js')(alerts)
  103. }
  104. })
  105. })