51 lines
1.6 KiB
JavaScript
Raw Normal View History

import { POPUP_RESULT, POPUP_TYPE, Popup } from './popup.js';
2023-10-31 22:16:33 +02:00
const ELEMENT_ID = 'loader';
/** @type {Popup} */
let loaderPopup;
2023-10-31 22:16:33 +02: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
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>
</div>`, POPUP_TYPE.DISPLAY, null, { transparent: true, animation: 'fast' });
// No close button, loaders are not closable
loaderPopup.closeButton.style.display = 'none';
loaderPopup.show();
2024-04-08 00:18:21 +09:00
}
export async function hideLoader() {
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 20:44:29 +02:00
return new Promise((resolve) => {
//Sets up a 2-step animation. Spinner blurs/fades out, and then the loader shadow does the same.
$('#load-spinner').on('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function () {
$(`#${ELEMENT_ID}`)
//only fade out the spinner and replace with login screen
.animate({ opacity: 0 }, 300, function () {
$(`#${ELEMENT_ID}`).remove();
loaderPopup.complete(POPUP_RESULT.AFFIRMATIVE).then(() => {
loaderPopup = null;
resolve();
});
});
2023-12-02 21:11:06 +02:00
});
2024-06-30 20:44:29 +02:00
$('#load-spinner')
.css({
'filter': 'blur(15px)',
'opacity': '0',
});
});
2023-12-03 14:23:20 +02:00
}
2024-06-30 20:44:29 +02:00