wikijs-fork/client/js/app.js

202 lines
5.9 KiB
JavaScript
Raw Normal View History

2017-02-09 01:52:37 +00:00
'use strict'
2017-06-11 21:55:06 +00:00
/* global $ */
2017-05-21 03:21:16 +00:00
/* eslint-disable no-new */
2017-03-27 02:07:40 +00:00
2017-05-21 03:21:16 +00:00
import Vue from 'vue'
import VueResource from 'vue-resource'
2017-05-22 17:32:52 +00:00
import VueClipboards from 'vue-clipboards'
import VueLodash from 'vue-lodash'
import store from './store'
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'
import 'jquery-contextmenu'
import 'jquery-simple-upload'
import 'jquery-smooth-scroll'
import 'jquery-sticky'
// ====================================
// Load minimal lodash
// ====================================
import cloneDeep from 'lodash/cloneDeep'
import concat from 'lodash/concat'
import debounce from 'lodash/debounce'
import deburr from 'lodash/deburr'
import delay from 'lodash/delay'
import filter from 'lodash/filter'
import find from 'lodash/find'
import findKey from 'lodash/findKey'
import forEach from 'lodash/forEach'
import includes from 'lodash/includes'
import isBoolean from 'lodash/isBoolean'
import isEmpty from 'lodash/isEmpty'
import isNil from 'lodash/isNil'
import join from 'lodash/join'
import kebabCase from 'lodash/kebabCase'
import last from 'lodash/last'
import map from 'lodash/map'
import nth from 'lodash/nth'
import pullAt from 'lodash/pullAt'
import reject from 'lodash/reject'
import slice from 'lodash/slice'
import split from 'lodash/split'
import startCase from 'lodash/startCase'
import toString from 'lodash/toString'
import toUpper from 'lodash/toUpper'
import trim from 'lodash/trim'
// ====================================
// Load Helpers
// ====================================
import helpers from './helpers'
2017-05-21 03:21:16 +00:00
// ====================================
// Load Vue Components
// ====================================
import alertComponent from './components/alert.vue'
2017-05-21 03:21:16 +00:00
import anchorComponent from './components/anchor.vue'
import colorPickerComponent from './components/color-picker.vue'
import editorCodeblockComponent from './components/editor-codeblock.vue'
import editorFileComponent from './components/editor-file.vue'
import editorVideoComponent from './components/editor-video.vue'
2017-05-21 03:21:16 +00:00
import loadingSpinnerComponent from './components/loading-spinner.vue'
import modalCreatePageComponent from './components/modal-create-page.vue'
import modalCreateUserComponent from './components/modal-create-user.vue'
import modalDeleteUserComponent from './components/modal-delete-user.vue'
import modalDiscardPageComponent from './components/modal-discard-page.vue'
import modalMovePageComponent from './components/modal-move-page.vue'
2017-06-12 01:11:01 +00:00
import modalProfile2faComponent from './components/modal-profile-2fa.vue'
import modalUpgradeSystemComponent from './components/modal-upgrade-system.vue'
import pageLoaderComponent from './components/page-loader.vue'
2017-05-21 03:21:16 +00:00
import searchComponent from './components/search.vue'
2017-05-21 22:58:19 +00:00
import treeComponent from './components/tree.vue'
2017-05-21 03:21:16 +00:00
import adminEditUserComponent from './pages/admin-edit-user.component.js'
2017-05-21 03:21:16 +00:00
import adminProfileComponent from './pages/admin-profile.component.js'
import adminSettingsComponent from './pages/admin-settings.component.js'
import contentViewComponent from './pages/content-view.component.js'
import editorComponent from './components/editor.component.js'
import sourceViewComponent from './pages/source-view.component.js'
2017-05-21 03:21:16 +00:00
// ====================================
// Build lodash object
// ====================================
const _ = {
deburr,
concat,
cloneDeep,
debounce,
delay,
filter,
find,
findKey,
forEach,
includes,
isBoolean,
isEmpty,
isNil,
join,
kebabCase,
last,
map,
nth,
pullAt,
reject,
slice,
split,
startCase,
toString,
toUpper,
trim
}
2017-05-21 03:21:16 +00:00
// ====================================
// Initialize Vue Modules
2017-05-21 03:21:16 +00:00
// ====================================
Vue.use(VueResource)
2017-05-22 17:32:52 +00:00
Vue.use(VueClipboards)
2017-05-21 03:21:16 +00:00
Vue.use(VueI18Next)
Vue.use(VueLodash, _)
Vue.use(helpers)
2017-05-21 03:21:16 +00:00
i18next
.use(i18nextXHR)
.init({
backend: {
loadPath: '/js/i18n/{{lng}}.json'
},
lng: siteLang,
fallbackLng: siteLang
})
$(() => {
// ====================================
// Notifications
// ====================================
2016-08-28 15:27:05 +00:00
2017-02-09 01:52:37 +00:00
$(window).bind('beforeunload', () => {
store.dispatch('startLoading')
2017-02-09 01:52:37 +00:00
})
$(document).ajaxSend(() => {
store.dispatch('startLoading')
2017-02-09 01:52:37 +00:00
}).ajaxComplete(() => {
store.dispatch('stopLoading')
2017-02-09 01:52:37 +00:00
})
2016-08-28 01:46:10 +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)
window.wikijs = new Vue({
mixins: [helpers],
2017-05-21 03:21:16 +00:00
components: {
alert: alertComponent,
adminEditUser: adminEditUserComponent,
2017-05-21 03:21:16 +00:00
adminProfile: adminProfileComponent,
adminSettings: adminSettingsComponent,
anchor: anchorComponent,
colorPicker: colorPickerComponent,
contentView: contentViewComponent,
editor: editorComponent,
editorCodeblock: editorCodeblockComponent,
editorFile: editorFileComponent,
editorVideo: editorVideoComponent,
2017-05-21 03:21:16 +00:00
loadingSpinner: loadingSpinnerComponent,
modalCreatePage: modalCreatePageComponent,
modalCreateUser: modalCreateUserComponent,
modalDeleteUser: modalDeleteUserComponent,
modalDiscardPage: modalDiscardPageComponent,
modalMovePage: modalMovePageComponent,
2017-06-12 01:11:01 +00:00
modalProfile2fa: modalProfile2faComponent,
modalUpgradeSystem: modalUpgradeSystemComponent,
pageLoader: pageLoaderComponent,
2017-05-21 22:58:19 +00:00
search: searchComponent,
sourceView: sourceViewComponent,
2017-05-21 22:58:19 +00:00
tree: treeComponent
},
2017-05-21 03:21:16 +00:00
store,
i18n,
el: '#root',
mounted() {
2017-05-22 17:32:52 +00:00
$('a:not(.toc-anchor)').smoothScroll({ speed: 500, offset: -50 })
$('#header').sticky({ topSpacing: 0 })
$('.sidebar-pagecontents').sticky({ topSpacing: 15, bottomSpacing: 75 })
}
2017-05-21 03:21:16 +00:00
})
2017-02-09 01:52:37 +00:00
})