2024-06-30 19:45:42 +02:00
|
|
|
import { POPUP_RESULT, POPUP_TYPE, Popup } from './popup.js';
|
|
|
|
|
|
|
|
/** @type {Popup} */
|
|
|
|
let loaderPopup;
|
|
|
|
|
2024-06-30 22:03:38 +02:00
|
|
|
let preloaderYoinked = false;
|
|
|
|
|
2023-10-31 21:16:33 +01:00
|
|
|
export function showLoader() {
|
2024-06-30 20:44:29 +02:00
|
|
|
// Two loaders don't make sense. Don't await, we can overlay the old loader while it closes
|
2024-06-30 19:45:42 +02:00
|
|
|
if (loaderPopup) loaderPopup.complete(POPUP_RESULT.CANCELLED);
|
|
|
|
|
|
|
|
loaderPopup = new Popup(`
|
|
|
|
<div id="loader">
|
|
|
|
<div id="load-spinner" class="fa-solid fa-gear fa-spin fa-3x"></div>
|
2024-06-30 22:27:49 +02:00
|
|
|
</div>`, POPUP_TYPE.DISPLAY, null, { transparent: true, animation: 'none' });
|
2024-06-30 19:45:42 +02:00
|
|
|
|
|
|
|
// No close button, loaders are not closable
|
|
|
|
loaderPopup.closeButton.style.display = 'none';
|
|
|
|
|
|
|
|
loaderPopup.show();
|
2024-04-07 17:18:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function hideLoader() {
|
2024-06-30 19:45:42 +02:00
|
|
|
if (!loaderPopup) {
|
|
|
|
console.warn('There is no loader showing to hide');
|
2024-06-30 20:44:29 +02:00
|
|
|
return Promise.resolve();
|
2024-06-30 19:45:42 +02:00
|
|
|
}
|
|
|
|
|
2024-06-30 20:44:29 +02:00
|
|
|
return new Promise((resolve) => {
|
2024-06-30 22:27:49 +02:00
|
|
|
// Spinner blurs/fades out
|
2024-06-30 20:44:29 +02:00
|
|
|
$('#load-spinner').on('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function () {
|
2024-07-04 00:41:21 +02:00
|
|
|
$('#loader').remove();
|
2024-06-30 22:27:49 +02:00
|
|
|
// Yoink preloader entirely; it only exists to cover up unstyled content while loading JS
|
|
|
|
// If it's present, we remove it once and then it's gone.
|
|
|
|
yoinkPreloader();
|
|
|
|
|
2024-06-30 22:17:23 +02:00
|
|
|
loaderPopup.complete(POPUP_RESULT.AFFIRMATIVE).then(() => {
|
|
|
|
loaderPopup = null;
|
|
|
|
resolve();
|
|
|
|
});
|
2023-12-02 20:11:06 +01:00
|
|
|
});
|
2024-06-30 19:45:42 +02:00
|
|
|
|
2024-06-30 20:44:29 +02:00
|
|
|
$('#load-spinner')
|
|
|
|
.css({
|
|
|
|
'filter': 'blur(15px)',
|
|
|
|
'opacity': '0',
|
|
|
|
});
|
|
|
|
});
|
2023-12-03 13:23:20 +01:00
|
|
|
}
|
2024-06-30 20:44:29 +02:00
|
|
|
|
2024-06-30 22:03:38 +02:00
|
|
|
function yoinkPreloader() {
|
|
|
|
if (preloaderYoinked) return;
|
|
|
|
document.getElementById('preloader').remove();
|
|
|
|
preloaderYoinked = true;
|
|
|
|
}
|