aboutsummaryrefslogtreecommitdiff
path: root/resources/assets/javascripts/chunks/vue.js
blob: 8d506a1dfc8c797a254db29ec796ce1107ff2e1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import Vue from 'vue';
import Vuex from 'vuex';
import Router from "vue-router";
import eventBus from '../lib/event-bus.ts';
import GetTextPlugin from 'vue-gettext';
import { getLocale, getVueConfig } from '../lib/gettext';
import PortalVue from 'portal-vue';
import BaseComponents from '../../../vue/base-components.js';
import BaseDirectives from "../../../vue/base-directives.js";
import StudipStore from "../../../vue/store/StudipStore.js";
import CKEditor from '@ckeditor/ckeditor5-vue2';

// Setup gettext
Vue.use(GetTextPlugin, getVueConfig());
eventBus.on('studip:set-locale', (locale) => {
    Vue.config.language = locale;
})

// Register global components and directives
registerGlobalComponents();
registerGlobalDirectives();

// Setup store and default Stud.IP store
Vue.use(Vuex);
const store = new Vuex.Store({});

store.registerModule('studip', StudipStore);

// Setup router and PortalVue
Vue.use(Router);
Vue.use(PortalVue);

// Define our own global mixin for Vue
Vue.mixin({
    methods: {
        globalEmit(...args) {
            eventBus.emit(...args);
        },
        globalOn(...args) {
            eventBus.on(...args);
        },
        globalOff(...args) {
            eventBus.off(...args);
        },
        getStudipConfig: store.getters['studip/getConfig']
    },
});

Vue.use(CKEditor);

// Define createApp function
function createApp(options, ...args) {
    Vue.config.language = getLocale();
    return new Vue({ store, ...options }, ...args);
}

// Define global registration functions for components and directives
function registerGlobalComponents() {
    for (const [name, component] of Object.entries(BaseComponents)) {
        Vue.component(name, component);
    }
}

function registerGlobalDirectives() {
    for (const [name, directive] of Object.entries(BaseDirectives)) {
        Vue.directive(name, directive);
    }
}

export { Vue, createApp, eventBus, store };