]> BookStack Code Mirror - bookstack/blob - resources/js/app.js
JS: Converted/updated translation code to TS, fixed some comment counts
[bookstack] / resources / js / app.js
1 import {EventManager} from './services/events.ts';
2 import {HttpManager} from './services/http.ts';
3 import {Translator} from './services/translations.ts';
4 import * as componentMap from './components';
5 import {ComponentStore} from './services/components.ts';
6
7 // eslint-disable-next-line no-underscore-dangle
8 window.__DEV__ = false;
9
10 // Url retrieval function
11 window.baseUrl = function baseUrl(path) {
12     let targetPath = path;
13     let basePath = document.querySelector('meta[name="base-url"]').getAttribute('content');
14     if (basePath[basePath.length - 1] === '/') basePath = basePath.slice(0, basePath.length - 1);
15     if (targetPath[0] === '/') targetPath = targetPath.slice(1);
16     return `${basePath}/${targetPath}`;
17 };
18
19 window.importVersioned = function importVersioned(moduleName) {
20     const version = document.querySelector('link[href*="/dist/styles.css?version="]').href.split('?version=').pop();
21     const importPath = window.baseUrl(`dist/${moduleName}.js?version=${version}`);
22     return import(importPath);
23 };
24
25 // Set events, http & translation services on window
26 window.$http = new HttpManager();
27 window.$events = new EventManager();
28 window.$trans = new Translator();
29
30 // Load & initialise components
31 window.$components = new ComponentStore();
32 window.$components.register(componentMap);
33 window.$components.init();