a
This commit is contained in:
parent
e2a9b7f4bd
commit
245c1ae7ec
|
|
@ -13,109 +13,45 @@
|
|||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div>
|
||||
<h1>Welcome to NFC Tools KBC - Test Page</h1>
|
||||
<p>Launch NFC Tools KBC, focus this web page then scan a tag. Current status:</p>
|
||||
<p id="kbc-target">Waiting for a tag</p>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
/*
|
||||
var NFCToolsKBC = (function () {
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const input = document.getElementById('donneesCarte');
|
||||
const form = document.getElementById('frmrechercheparcarte');
|
||||
|
||||
var instance = null; // Singleton instance
|
||||
var callback = null; // Callback function
|
||||
var isAlreadyRegister = false; // Is event already register ?
|
||||
let buffer = '';
|
||||
let timer = null;
|
||||
|
||||
function create () {
|
||||
function registerCallback(callback) {
|
||||
// Capture globale (lecteur NFC = clavier)
|
||||
document.addEventListener('keydown', function (e) {
|
||||
|
||||
// Check if callback param is a function
|
||||
if (typeof callback == 'function') {
|
||||
this.callback = callback; // Then, save the callback reference
|
||||
|
||||
// Register the event if is not already registered
|
||||
if(this.callback != null && !isAlreadyRegister) {
|
||||
document.addEventListener('paste', (event) => {
|
||||
this.callback((event.clipboardData || window.clipboardData).getData('text')); // Call the callback function
|
||||
event.preventDefault(); // To block the default event handling
|
||||
});
|
||||
isAlreadyRegister = true; // Event is now registered
|
||||
// ENTER → soumission immédiate
|
||||
if (e.key === 'Enter') {
|
||||
if (buffer.length > 0) {
|
||||
input.value = buffer;
|
||||
buffer = '';
|
||||
form.submit();
|
||||
}
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// You must pass a function as a callback
|
||||
console.log("Error: Unable to register callback");
|
||||
}
|
||||
}
|
||||
return {
|
||||
registerCallback: registerCallback
|
||||
};
|
||||
}
|
||||
|
||||
// Get instance
|
||||
return {
|
||||
getInstance: function() {
|
||||
if(instance == null) {
|
||||
instance = create();
|
||||
}
|
||||
return instance; // Return singleton
|
||||
}
|
||||
};
|
||||
})();
|
||||
// Ignorer touches spéciales
|
||||
if (e.key.length > 1) return;
|
||||
|
||||
// Wait for the HTML document has been completely loaded and parsed
|
||||
document.addEventListener("DOMContentLoaded", function(event) {
|
||||
// Accumuler caractères scannés
|
||||
buffer += e.key;
|
||||
|
||||
// Here we register a callback function to get the NFC tag's content
|
||||
alert("NFCToolsKBC");
|
||||
NFCToolsKBC.getInstance().registerCallback(function(content){
|
||||
// Do what you want here with the content
|
||||
|
||||
// For the demo, we show the content in a HTML element
|
||||
var target = document.getElementById("kbc-target");
|
||||
target.innerHTML = "Content detected: " + content;
|
||||
});
|
||||
|
||||
});
|
||||
*/
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const input = document.getElementById('donneesCarte');
|
||||
const form = document.getElementById('frmrechercheparcarte');
|
||||
|
||||
let buffer = '';
|
||||
let timer = null;
|
||||
|
||||
// Capture globale (lecteur NFC = clavier)
|
||||
document.addEventListener('keydown', function (e) {
|
||||
|
||||
// ENTER → soumission immédiate
|
||||
if (e.key === 'Enter') {
|
||||
if (buffer.length > 0) {
|
||||
input.value = buffer;
|
||||
buffer = '';
|
||||
form.submit();
|
||||
}
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
// Ignorer touches spéciales
|
||||
if (e.key.length > 1) return;
|
||||
|
||||
// Accumuler caractères scannés
|
||||
buffer += e.key;
|
||||
|
||||
// Reset après 300 ms d'inactivité (sécurité)
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => {
|
||||
if (buffer.length > 0) {
|
||||
input.value = buffer;
|
||||
buffer = '';
|
||||
form.submit();
|
||||
}
|
||||
}, 300);
|
||||
});
|
||||
});
|
||||
// Reset après 300 ms d'inactivité (sécurité)
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => {
|
||||
if (buffer.length > 0) {
|
||||
input.value = buffer;
|
||||
buffer = '';
|
||||
form.submit();
|
||||
}
|
||||
}, 300);
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user