]> BookStack Code Mirror - bookstack/blob - resources/js/app.js
Lexical: Altered keyboard handling to indicant handled state
[bookstack] / resources / js / app.js
1 import {EventManager} from './services/events.ts';
2 import {HttpManager} from './services/http.ts';
3 import Translations from './services/translations';
4 import * as componentMap from './components';
5 import {ComponentStore} from './services/components.ts';
6
7 // Url retrieval function
8 window.baseUrl = function baseUrl(path) {
9     let targetPath = path;
10     let basePath = document.querySelector('meta[name="base-url"]').getAttribute('content');
11     if (basePath[basePath.length - 1] === '/') basePath = basePath.slice(0, basePath.length - 1);
12     if (targetPath[0] === '/') targetPath = targetPath.slice(1);
13     return `${basePath}/${targetPath}`;
14 };
15
16 window.importVersioned = function importVersioned(moduleName) {
17     const version = document.querySelector('link[href*="/dist/styles.css?version="]').href.split('?version=').pop();
18     const importPath = window.baseUrl(`dist/${moduleName}.js?version=${version}`);
19     return import(importPath);
20 };
21
22 // Set events and http services on window
23 window.$http = new HttpManager();
24 window.$events = new EventManager();
25
26 // Translation setup
27 // Creates a global function with name 'trans' to be used in the same way as the Laravel translation system
28 const translator = new Translations();
29 window.trans = translator.get.bind(translator);
30 window.trans_choice = translator.getPlural.bind(translator);
31 window.trans_plural = translator.parsePlural.bind(translator);
32
33 // Load & initialise components
34 window.$components = new ComponentStore();
35 window.$components.register(componentMap);
36 window.$components.init();