2024-07-18 18:19:11 +08:00
|
|
|
import {EventManager} from './services/events.ts';
|
2024-07-18 22:13:14 +08:00
|
|
|
import {HttpManager} from './services/http.ts';
|
2024-10-08 05:55:10 +08:00
|
|
|
import {Translator} from './services/translations.ts';
|
2023-04-19 05:20:02 +08:00
|
|
|
import * as componentMap from './components';
|
2024-07-03 18:00:57 +08:00
|
|
|
import {ComponentStore} from './services/components.ts';
|
2023-04-19 05:20:02 +08:00
|
|
|
|
2024-09-18 20:43:39 +08:00
|
|
|
// eslint-disable-next-line no-underscore-dangle
|
|
|
|
window.__DEV__ = false;
|
|
|
|
|
2016-08-14 19:29:35 +08:00
|
|
|
// Url retrieval function
|
2023-04-19 17:46:13 +08:00
|
|
|
window.baseUrl = function baseUrl(path) {
|
|
|
|
let targetPath = path;
|
2016-08-14 19:29:35 +08:00
|
|
|
let basePath = document.querySelector('meta[name="base-url"]').getAttribute('content');
|
2023-04-19 05:20:02 +08:00
|
|
|
if (basePath[basePath.length - 1] === '/') basePath = basePath.slice(0, basePath.length - 1);
|
2023-04-19 17:46:13 +08:00
|
|
|
if (targetPath[0] === '/') targetPath = targetPath.slice(1);
|
|
|
|
return `${basePath}/${targetPath}`;
|
2016-08-14 19:29:35 +08:00
|
|
|
};
|
|
|
|
|
2023-04-19 17:46:13 +08:00
|
|
|
window.importVersioned = function importVersioned(moduleName) {
|
2022-02-08 19:10:01 +08:00
|
|
|
const version = document.querySelector('link[href*="/dist/styles.css?version="]').href.split('?version=').pop();
|
|
|
|
const importPath = window.baseUrl(`dist/${moduleName}.js?version=${version}`);
|
|
|
|
return import(importPath);
|
|
|
|
};
|
|
|
|
|
2024-10-08 05:55:10 +08:00
|
|
|
// Set events, http & translation services on window
|
2024-07-18 22:13:14 +08:00
|
|
|
window.$http = new HttpManager();
|
2024-07-18 18:19:11 +08:00
|
|
|
window.$events = new EventManager();
|
2024-10-08 05:55:10 +08:00
|
|
|
window.$trans = new Translator();
|
2016-12-31 22:27:40 +08:00
|
|
|
|
2023-04-19 05:20:02 +08:00
|
|
|
// Load & initialise components
|
2024-07-03 18:00:57 +08:00
|
|
|
window.$components = new ComponentStore();
|
|
|
|
window.$components.register(componentMap);
|
|
|
|
window.$components.init();
|