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';
7 // Url retrieval function
8 window.baseUrl = function baseUrl(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}`;
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);
22 // Set events and http services on window
23 window.$http = new HttpManager();
24 window.$events = new EventManager();
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);
33 // Load & initialise components
34 window.$components = new ComponentStore();
35 window.$components.register(componentMap);
36 window.$components.init();