This commit updates the MS1 loader to include a message parameter for inline HTML usage, ensuring consistent messaging during AJAX operations. Additionally, new functions are introduced to render loading indicators and assets, improving user feedback during data synchronization processes. The integration of these features aims to enhance the overall user experience and clarity within the ChronoTrack API admin interface.
65 lines
1.8 KiB
JavaScript
65 lines
1.8 KiB
JavaScript
/**
|
|
* MS1 — Loader coureur (overlay + inline).
|
|
* Usage : Ms1Loader.show() / Ms1Loader.hide() / Ms1Loader.inlineHtml(message)
|
|
* Norme MS1 : tout message d'attente AJAX/panel doit utiliser Ms1Loader.inlineHtml().
|
|
*/
|
|
(function (global, $) {
|
|
'use strict';
|
|
|
|
var config = {
|
|
src: '/images/ms1-runner-loader.gif',
|
|
labelWait: 'Chargement...'
|
|
};
|
|
|
|
function escHtml(str) {
|
|
return String(str == null ? '' : str)
|
|
.replace(/&/g, '&')
|
|
.replace(/</g, '<')
|
|
.replace(/>/g, '>')
|
|
.replace(/"/g, '"');
|
|
}
|
|
|
|
function runnerImg() {
|
|
return '<img class="ms1-loader__runner" src="' + escHtml(config.src) + '" alt="" role="presentation" decoding="async">';
|
|
}
|
|
|
|
function init(options) {
|
|
if (options) {
|
|
$.extend(config, options);
|
|
}
|
|
}
|
|
|
|
function inlineHtml(message) {
|
|
var msg = message == null || message === '' ? config.labelWait : message;
|
|
return '<div class="ms1-loader ms1-loader--inline" role="status" aria-live="polite" aria-busy="true">'
|
|
+ runnerImg()
|
|
+ '<span class="ms1-loader__label">' + escHtml(msg) + '</span>'
|
|
+ '</div>';
|
|
}
|
|
|
|
function show(message) {
|
|
var $preloader = $('#preloader');
|
|
if (!$preloader.length) {
|
|
return;
|
|
}
|
|
if (message != null && message !== '') {
|
|
var $text = $('#preloader_text');
|
|
if ($text.length) {
|
|
$text.html(message);
|
|
}
|
|
}
|
|
$preloader.show();
|
|
}
|
|
|
|
function hide() {
|
|
$('#preloader').fadeOut('slow');
|
|
}
|
|
|
|
global.Ms1Loader = {
|
|
init: init,
|
|
inlineHtml: inlineHtml,
|
|
show: show,
|
|
hide: hide
|
|
};
|
|
}(window, jQuery));
|