webpack-bootstrap-ui-kit/src/js/main/main.js

86 lines
1.8 KiB
JavaScript
Raw Normal View History

2021-08-18 20:51:15 +02:00
import Events from "../_events";
import Consts from "../_consts";
import SpinnerUI from "./loading-spinner";
2021-08-09 18:04:09 +02:00
const MainUI = ((W) => {
2021-08-18 20:51:15 +02:00
const NAME = "_main";
2021-08-09 18:04:09 +02:00
const D = document;
const BODY = D.body;
console.info(
`%cUI Kit ${UINAME} ${UIVERSION}`,
2021-08-18 20:51:15 +02:00
"color:yellow;font-size:14px"
2021-08-09 18:04:09 +02:00
);
console.info(
`%c${UIMetaNAME} ${UIMetaVersion}`,
2021-08-18 20:51:15 +02: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-08-18 20:51:15 +02:00
"color:yellow;font-size:10px"
2021-08-09 18:04:09 +02:00
);
2021-08-18 20:51:15 +02: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-08-18 20:51:15 +02:00
console.groupEnd("Events");
2021-08-09 18:04:09 +02:00
2021-08-18 20:51:15 +02:00
console.groupCollapsed("Consts");
2021-08-09 18:04:09 +02:00
Object.keys(Consts).forEach((k) => {
console.info(`${k}: ${Consts[k]}`);
});
2021-08-18 20:51:15 +02:00
console.groupEnd("Events");
2021-08-09 18:04:09 +02:00
2021-08-18 20:51:15 +02: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
W.history.replaceState(
{
landing: W.location.href,
},
D.title,
2021-08-18 20:51:15 +02:00
W.location.href
2021-08-09 18:04:09 +02:00
);
//
ui.loaded();
}
// init AJAX components
static loaded() {
const ui = this;
console.log(`${NAME}: loaded`);
}
}
W.addEventListener(`${Events.LOADED}`, () => {
MainUI.init();
2021-08-18 20:51:15 +02:00
BODY.classList.add("loaded");
2021-08-09 18:04:09 +02:00
SpinnerUI.hide();
2021-08-18 20:51:15 +02:00
console.groupEnd("init");
console.timeEnd("init");
2021-08-09 18:04:09 +02:00
W.dispatchEvent(new Event(Events.LODEDANDREADY));
});
W.addEventListener(`${Events.AJAX}`, () => {
MainUI.loaded();
});
W.MainUI = MainUI;
return MainUI;
})(window);
export default MainUI;