wikijs-fork/client/js/app.js

134 lines
3.2 KiB
JavaScript
Raw Normal View History

2017-02-09 01:52:37 +00:00
'use strict'
2017-05-21 03:21:16 +00:00
/* global alertsData, siteLang */
/* eslint-disable no-new */
2017-03-27 02:07:40 +00:00
import $ from 'jquery'
2017-03-27 02:07:40 +00:00
import _ from 'lodash'
2017-05-21 03:21:16 +00:00
import Vue from 'vue'
import Vuex from 'vuex'
2017-03-27 02:07:40 +00:00
import io from 'socket.io-client'
2017-05-21 03:21:16 +00:00
import i18next from 'i18next'
import i18nextXHR from 'i18next-xhr-backend'
import VueI18Next from '@panter/vue-i18next'
2017-03-27 02:07:40 +00:00
import Alerts from './components/alerts.js'
import 'jquery-smooth-scroll'
import 'jquery-sticky'
2017-05-21 03:21:16 +00:00
// ====================================
// Load Vue Components
// ====================================
import anchorComponent from './components/anchor.vue'
import colorPickerComponent from './components/color-picker.vue'
import loadingSpinnerComponent from './components/loading-spinner.vue'
import searchComponent from './components/search.vue'
import adminProfileComponent from './pages/admin-profile.component.js'
import adminSettingsComponent from './pages/admin-settings.component.js'
// ====================================
// Initialize i18next
// ====================================
Vue.use(VueI18Next)
i18next
.use(i18nextXHR)
.init({
backend: {
loadPath: '/js/i18n/{{lng}}.json'
},
lng: siteLang,
fallbackLng: siteLang
})
// ====================================
// Initialize Vuex
// ====================================
Vue.use(Vuex)
const store = new Vuex.Store({
state: {
loading: false
},
mutations: {
startLoading: state => { state.loading = true },
stopLoading: state => { state.loading = false }
}
})
$(() => {
// ====================================
// Scroll
// ====================================
2016-08-28 01:46:10 +00:00
2017-02-09 01:52:37 +00:00
$('a').smoothScroll({
2017-04-30 04:21:28 +00:00
speed: 500,
offset: -50
2017-02-09 01:52:37 +00:00
})
$('#header').sticky({ topSpacing: 0 })
$('.sidebar-pagecontents').sticky({ topSpacing: 15, bottomSpacing: 75 })
// ====================================
// Notifications
// ====================================
2016-08-28 15:27:05 +00:00
2017-02-09 01:52:37 +00:00
$(window).bind('beforeunload', () => {
2017-05-21 03:21:16 +00:00
store.commit('startLoading')
2017-02-09 01:52:37 +00:00
})
$(document).ajaxSend(() => {
2017-05-21 03:21:16 +00:00
store.commit('startLoading')
2017-02-09 01:52:37 +00:00
}).ajaxComplete(() => {
2017-05-21 03:21:16 +00:00
store.commit('stopLoading')
2017-02-09 01:52:37 +00:00
})
2016-08-28 01:46:10 +00:00
2017-05-21 03:21:16 +00:00
var alerts = {}
/*var alerts = new Alerts()
2017-02-09 01:52:37 +00:00
if (alertsData) {
_.forEach(alertsData, (alertRow) => {
alerts.push(alertRow)
})
2017-05-21 03:21:16 +00:00
}*/
2016-08-24 01:09:09 +00:00
// ====================================
// Establish WebSocket connection
// ====================================
2017-05-21 03:21:16 +00:00
let socket = io(window.location.origin)
window.socket = socket
2017-05-21 03:21:16 +00:00
// ====================================
// Bootstrap Vue
// ====================================
const i18n = new VueI18Next(i18next)
new Vue({
components: {
adminProfile: adminProfileComponent,
adminSettings: adminSettingsComponent,
anchor: anchorComponent,
colorPicker: colorPickerComponent,
loadingSpinner: loadingSpinnerComponent,
search: searchComponent
},
store,
i18n,
el: '#root'
})
// ====================================
// Pages logic
// ====================================
2016-08-28 15:27:05 +00:00
require('./pages/view.js')(alerts)
require('./pages/all.js')(alerts, socket)
require('./pages/create.js')(alerts, socket)
require('./pages/edit.js')(alerts, socket)
require('./pages/source.js')(alerts)
require('./pages/history.js')(alerts)
require('./pages/admin.js')(alerts)
2017-02-09 01:52:37 +00:00
})