Files
ms1inscription-v5/js/ms1-loader.js
stephan d7f3b0156b Implement MS1 loader functionality and update preloader UI
This commit introduces the MS1 loader functionality across various scripts, enhancing the user experience during loading processes. It integrates the loader into form submissions and AJAX calls, ensuring consistent feedback for users. Additionally, the preloader UI is updated to utilize the new loader design, improving visual consistency. The version code is incremented to reflect these changes.
2026-07-02 09:14:34 -04:00

64 lines
1.7 KiB
JavaScript

/**
* MS1 — Loader coureur (overlay + inline).
* Usage : Ms1Loader.show() / Ms1Loader.hide() / 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, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
}
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));