@geogirafe/lib-geoportal
Version:
GeoGirafe is a flexible application to build online geoportals.
38 lines (37 loc) • 1.91 kB
JavaScript
import ConfigManager from './tools/configuration/configmanager';
import OfflineManager from './tools/offline/offlinemanager';
import MapComponent from './components/map/component';
import MobileSearchComponent from './components/search-mobile/component';
import MobileThemeComponent from './components/themes-mobile/component';
import OfflineComponent from './components/offline/component';
import { initialize } from './initialize';
// Redirect to desktop interface if we are NOT on mobile
if (!navigator.userAgent.includes('iPhone') && !navigator.userAgent.includes('Android')) {
window.location.href = 'index.html';
}
// Tell configManager it should load the mobile configuration as well
ConfigManager.getInstance().initMobile();
// Common initialization
initialize().then(() => {
if (window.cordova) {
// If this runs in Cordova, we have to wait the deviceready event to be able to use the connectivity plugin
document.addEventListener('deviceready', () => {
const networkState = navigator.connection.type;
const isOffline = networkState === Connection.NONE;
OfflineManager.getInstance().initializeOfflineState(isOffline);
}, false);
}
else {
// Otherwise, just do it without waiting
OfflineManager.getInstance().initializeOfflineState(!navigator.onLine);
}
// Define components names
customElements.define('girafe-map', MapComponent);
customElements.define('girafe-search', MobileSearchComponent);
customElements.define('girafe-theme-select', MobileThemeComponent);
customElements.define('girafe-offline', OfflineComponent);
// To prevent the FOUC effect (flash of unstyled content),
// the html element is set to invisible when the application starts.
// When all elements have been declared, the html element is made visible
document.documentElement.style.opacity = '1';
});