prestation/Vue/Rechercheparcarte/index.php
2026-02-16 01:21:41 +00:00

74 lines
2.6 KiB
PHP
Executable File

<script>
const inputField = document.getElementById('donneesCarte');
const indicator = document.getElementById('reading-indicator');
const indicatorText = document.getElementById('indicator-text');
// Protection
inputField.addEventListener('contextmenu', e => e.preventDefault());
inputField.addEventListener('copy', e => e.preventDefault());
inputField.addEventListener('cut', e => e.preventDefault());
// ========== MAINTIEN DU FOCUS (Solution combinée optimale) ==========
// 1. Empêcher la perte de focus
inputField.addEventListener('blur', function(e) {
setTimeout(() => this.focus(), 10);
});
// 2. Surveillance par intervalle (backup)
const focusInterval = setInterval(function() {
if (document.activeElement !== inputField && !document.hidden) {
inputField.focus();
}
}, 200);
// 3. Capturer toutes les touches vers le champ
document.addEventListener('keydown', function(e) {
if (!e.ctrlKey && !e.altKey && !e.metaKey && document.activeElement !== inputField) {
inputField.focus();
}
});
// Nettoyage à la soumission du formulaire
document.getElementById('frmrechercheparcarte').addEventListener('submit', function() {
clearInterval(focusInterval);
});
// Détection du type de scan
function detectScanType(value) {
if (value.endsWith('qr') {
return 'qr';
}
return 'nfc';
}
inputField.addEventListener('input', function() {
if (this.value.length > 0) {
this.classList.add('reading');
indicator.classList.add('active');
const type = detectScanType(this.value);
indicatorText.textContent = type === 'qr'
? '<?= _("QR code détecté") ?>'
: '<?= _("Carte détectée") ?>';
} else {
this.classList.remove('reading');
indicator.classList.remove('active');
}
});
inputField.addEventListener('change', function () {
if (this.value.length > 3) {
const type = detectScanType(this.value);
const message = type === 'qr'
? '<?= _("Traitement du QR code...") ?>'
: '<?= _("Lecture de la carte...") ?>';
$('#div_wait_nfc').html('<div style="padding-top:80px; text-align:center; font-size:14px; color: #4caf50;"><span><i class="fa fa-spinner fa-spin fa-5x"></i></span><p style="margin-top:20px;">' + message + '</p></div>');
this.form.submit();
}
});
// Focus initial
window.addEventListener('load', () => inputField.focus());
document.addEventListener('DOMContentLoaded', () => inputField.focus());
</script>