]> BookStack Code Mirror - bookstack/blob - resources/js/app.js
Ran eslint fix on existing codebase
[bookstack] / resources / js / app.js
1 import events from './services/events';
2 import httpInstance from './services/http';
3 import Translations from './services/translations';
4
5 import * as components from './services/components';
6 import * as componentMap from './components';
7
8 // Url retrieval function
9 window.baseUrl = function(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 (path[0] === '/') path = path.slice(1);
13     return `${basePath}/${path}`;
14 };
15
16 window.importVersioned = function(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 = httpInstance;
24 window.$events = events;
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 components.register(componentMap);
35 window.$components = components;
36 components.init();