Chatwoot/app/javascript/packs/application.js

120 lines
3.2 KiB
JavaScript
Raw Normal View History

/* eslint no-console: 0 */
/* eslint-env browser */
/* eslint-disable no-new */
/* Vue Core */
import Vue from 'vue';
import VueI18n from 'vue-i18n';
import VueRouter from 'vue-router';
import axios from 'axios';
// Global Components
import hljs from 'highlight.js';
import Multiselect from 'vue-multiselect';
2021-06-06 11:29:05 +00:00
import VueFormulate from '@braid/vue-formulate';
import WootSwitch from 'components/ui/Switch';
import WootWizard from 'components/ui/Wizard';
import { sync } from 'vuex-router-sync';
import Vuelidate from 'vuelidate';
import VTooltip from 'v-tooltip';
2019-10-16 09:06:17 +00:00
import WootUiKit from '../dashboard/components';
import App from '../dashboard/App';
import i18n from '../dashboard/i18n';
import createAxios from '../dashboard/helper/APIHelper';
2021-06-06 11:29:05 +00:00
import commonHelpers, { isJSONValid } from '../dashboard/helper/commons';
import {
getAlertAudio,
initOnEvents,
} from '../shared/helpers/AudioNotificationHelper';
import { initFaviconSwitcher } from '../shared/helpers/faviconHelper';
import router, { initalizeRouter } from '../dashboard/routes';
2019-10-16 09:06:17 +00:00
import store from '../dashboard/store';
import constants from '../dashboard/constants';
import * as Sentry from '@sentry/vue';
import 'vue-easytable/libs/theme-default/index.css';
import { Integrations } from '@sentry/tracing';
import posthog from 'posthog-js';
import {
initializeAnalyticsEvents,
initializeChatwootEvents,
} from '../dashboard/helper/scriptHelpers';
import FluentIcon from 'shared/components/FluentIcon/DashboardIcon';
2022-04-21 05:57:28 +00:00
import VueDOMPurifyHTML from 'vue-dompurify-html';
import { domPurifyConfig } from '../shared/helpers/HTMLSanitizer';
Vue.config.env = process.env;
if (window.errorLoggingConfig) {
Sentry.init({
Vue,
dsn: window.errorLoggingConfig,
integrations: [new Integrations.BrowserTracing()],
});
}
if (window.analyticsConfig) {
posthog.init(window.analyticsConfig.token, {
api_host: window.analyticsConfig.host,
});
}
Vue.use(VueDOMPurifyHTML, domPurifyConfig);
Vue.use(VueRouter);
Vue.use(VueI18n);
Vue.use(WootUiKit);
Vue.use(Vuelidate);
2021-06-06 11:29:05 +00:00
Vue.use(VueFormulate, {
rules: {
JSON: ({ value }) => isJSONValid(value),
},
});
Vue.use(VTooltip, {
defaultHtml: false,
});
Vue.use(hljs.vuePlugin);
Vue.component('multiselect', Multiselect);
Vue.component('woot-switch', WootSwitch);
Vue.component('woot-wizard', WootWizard);
Vue.component('fluent-icon', FluentIcon);
const i18nConfig = new VueI18n({
locale: 'en',
messages: i18n,
});
sync(store, router);
// load common helpers into js
commonHelpers();
window.WootConstants = constants;
window.axios = createAxios(axios);
window.bus = new Vue();
initializeChatwootEvents();
initializeAnalyticsEvents();
initalizeRouter();
2019-08-21 04:57:57 +00:00
window.onload = () => {
window.WOOT = new Vue({
router,
store,
i18n: i18nConfig,
components: { App },
template: '<App/>',
}).$mount('#app');
2019-08-21 04:57:57 +00:00
};
const setupAudioListeners = () => {
getAlertAudio().then(() => {
initOnEvents.forEach(event => {
document.removeEventListener(event, setupAudioListeners, false);
});
});
};
window.addEventListener('load', () => {
window.playAudioAlert = () => {};
initOnEvents.forEach(e => {
document.addEventListener(e, setupAudioListeners, false);
});
initFaviconSwitcher();
});