2021-11-12 07:27:48 +01:00
|
|
|
import Events from '../_events';
|
|
|
|
import Consts from '../_consts';
|
|
|
|
import SpinnerUI from './loading-spinner';
|
2021-08-09 18:04:09 +02:00
|
|
|
|
2021-11-12 07:27:48 +01:00
|
|
|
const MainUI = ((window) => {
|
|
|
|
const NAME = '_main';
|
|
|
|
const BODY = document.body;
|
2021-08-09 18:04:09 +02:00
|
|
|
|
|
|
|
console.info(
|
|
|
|
`%cUI Kit ${UINAME} ${UIVERSION}`,
|
2021-11-12 07:27:48 +01:00
|
|
|
'color:yellow;font-size:14px'
|
2021-08-09 18:04:09 +02:00
|
|
|
);
|
|
|
|
console.info(
|
|
|
|
`%c${UIMetaNAME} ${UIMetaVersion}`,
|
2021-11-12 07:27:48 +01:00
|
|
|
'color:yellow;font-size:12px'
|
2021-08-09 18:04:09 +02:00
|
|
|
);
|
|
|
|
console.info(
|
|
|
|
`%chttps://github.com/a2nt/webpack-bootstrap-ui-kit by ${UIAUTHOR}`,
|
2021-11-12 07:27:48 +01:00
|
|
|
'color:yellow;font-size:10px'
|
2021-08-09 18:04:09 +02:00
|
|
|
);
|
|
|
|
|
2021-11-12 07:27:48 +01:00
|
|
|
console.info(`%cENV: ${process.env.NODE_ENV}`, 'color:green;font-size:10px');
|
|
|
|
console.groupCollapsed('Events');
|
2021-08-09 18:04:09 +02:00
|
|
|
Object.keys(Events).forEach((k) => {
|
|
|
|
console.info(`${k}: ${Events[k]}`);
|
|
|
|
});
|
2021-11-12 07:27:48 +01:00
|
|
|
console.groupEnd('Events');
|
2021-08-09 18:04:09 +02:00
|
|
|
|
2021-11-12 07:27:48 +01:00
|
|
|
console.groupCollapsed('Consts');
|
2021-08-09 18:04:09 +02:00
|
|
|
Object.keys(Consts).forEach((k) => {
|
|
|
|
console.info(`${k}: ${Consts[k]}`);
|
|
|
|
});
|
2021-11-12 07:27:48 +01:00
|
|
|
console.groupEnd('Events');
|
2021-08-09 18:04:09 +02:00
|
|
|
|
2021-11-12 07:27:48 +01:00
|
|
|
console.groupCollapsed('Init');
|
|
|
|
console.time('init');
|
2021-08-09 18:04:09 +02:00
|
|
|
|
|
|
|
class MainUI {
|
|
|
|
// first time the website initialization
|
|
|
|
static init() {
|
|
|
|
const ui = this;
|
|
|
|
|
|
|
|
// store landing page state
|
2021-11-12 07:27:48 +01:00
|
|
|
window.history.replaceState(
|
2021-08-09 18:04:09 +02:00
|
|
|
{
|
2021-11-12 07:27:48 +01:00
|
|
|
landing: window.location.href,
|
2021-08-09 18:04:09 +02:00
|
|
|
},
|
2021-11-12 07:27:48 +01:00
|
|
|
document.title,
|
|
|
|
window.location.href
|
2021-08-09 18:04:09 +02:00
|
|
|
);
|
|
|
|
//
|
|
|
|
|
|
|
|
ui.loaded();
|
|
|
|
}
|
|
|
|
|
|
|
|
// init AJAX components
|
|
|
|
static loaded() {
|
|
|
|
const ui = this;
|
|
|
|
console.log(`${NAME}: loaded`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-12 07:27:48 +01:00
|
|
|
const documentInit = () => {
|
2021-08-09 18:04:09 +02:00
|
|
|
MainUI.init();
|
|
|
|
|
2021-11-12 07:27:48 +01:00
|
|
|
BODY.classList.add('loaded');
|
2021-08-09 18:04:09 +02:00
|
|
|
SpinnerUI.hide();
|
|
|
|
|
2021-11-12 07:27:48 +01:00
|
|
|
console.groupEnd('init');
|
|
|
|
console.timeEnd('init');
|
2021-08-09 18:04:09 +02:00
|
|
|
|
2021-11-12 07:34:34 +01:00
|
|
|
window.addEventListener(`${Events.LOADED}`, (event) => {
|
|
|
|
window.dispatchEvent(new Event(Events.LODEDANDREADY));
|
|
|
|
});
|
2021-11-12 07:27:48 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
if (document.readyState === 'loading') { // Loading hasn't finished yet
|
|
|
|
document.addEventListener(`${Events.DOMLOADED}`, documentInit);
|
|
|
|
}else {
|
|
|
|
documentInit();
|
|
|
|
}
|
2021-08-09 18:04:09 +02:00
|
|
|
|
2021-11-12 07:27:48 +01:00
|
|
|
window.addEventListener(`${Events.AJAX}`, () => {
|
2021-08-09 18:04:09 +02:00
|
|
|
MainUI.loaded();
|
|
|
|
});
|
|
|
|
|
2021-11-12 07:27:48 +01:00
|
|
|
window.MainUI = MainUI;
|
2021-08-09 18:04:09 +02:00
|
|
|
|
|
|
|
return MainUI;
|
|
|
|
})(window);
|
|
|
|
|
|
|
|
export default MainUI;
|