@geogirafe/lib-geoportal
Version:
GeoGirafe is a flexible application to build online geoportals.
59 lines (58 loc) • 2.27 kB
JavaScript
import GirafeHTMLElement from './base/GirafeHTMLElement.js';
export class SplashScreen {
splash;
begin() {
document.addEventListener('DOMContentLoaded', () => {
const element = document.getElementById('splash-screen');
if (!element) {
console.info('Nor SplashScreen found. Nothing to do.');
return;
}
this.splash = element;
// At this point, the config and translations have not been loaded yet
// Therefore, we hardcode this simple 'loading' text and use the browser configuration
this.setDefaultWaitingText();
});
}
setDefaultWaitingText() {
const language = navigator.language.toLowerCase();
console.debug(`Navigator language: ${language}`);
let loading = 'Loading...';
if (language.startsWith('fr')) {
loading = 'Chargement...';
}
else if (language.startsWith('de')) {
loading = 'Wird geladen...';
}
else if (language.startsWith('it')) {
loading = 'Caricamento...';
}
(this.splash?.getElementsByTagName('span')[0]).innerHTML = loading;
}
end() {
if (this.splash) {
this.splash.style.opacity = '0';
setTimeout(() => this.splash.remove(), 700);
}
}
}
export function redirectTo(page) {
const currentUrl = new URL(globalThis.location.href);
const mobileUrl = new URL(page, globalThis.location.origin);
const pathParts = currentUrl.pathname.split('/');
pathParts[pathParts.length - 1] = page;
mobileUrl.pathname = pathParts.join('/');
mobileUrl.search = currentUrl.search;
mobileUrl.hash = currentUrl.hash;
setTimeout(() => {
// Dispatch special event before redirecting, because some components need perhaps to do/cancel things
const event = new CustomEvent('gg:redirect');
globalThis.dispatchEvent(event);
globalThis.location.href = mobileUrl.toString();
});
}
export function initializeGeoGirafeCustomStyles(cssOverrides = {}) {
for (const [componentName, cssAsString] of Object.entries(cssOverrides)) {
GirafeHTMLElement.setCustomStyle(componentName, cssAsString);
}
}