/jquery-code-scanner

Lightweight handheld code scanner detector

Primary LanguageHTML

Jquery Code Scanner

This is a jquery plugin implementation of the simple and well working code snippet from Deadosaurus blog.
The aim here is to be able to get a scan code from anywhere in a web page.

You can try the plugin and see if it works with your code reader

How it works

A handheld scanner is exactly like a keyboard that will quickly enter the sequence of any scanned code.
The trick is rely on the speed of entry to suspect a scan.
More detail on the previously mentionned blog.

Installation

$ bower install jquery-code-scanner

Usage

Include the tool

<script src="js/jquery.min.js"></script>
<script src="js/jquery-code-scanner.js"></script>
<!-- ... -->
<input type="text" id="code-scan">

Initialize an input

$('#code-scan').codeScanner();

This input will receive any scanned code

Options

  • minEntryChars default: 8
    Minimum characters entered to be considered as a code reader

  • maxEntryTime default: 100
    Maximum time (in millisecond) to enter the characters to be considered as a code reader

$('#code-scan').codeScanner({
    maxEntryTime: 500, // milliseconds
    minEntryChars: 15  // characters
});

In this example, if 15 characters are not entered within 500ms, the string will not be taken as a scanned code

  • onScan default: Function setting the code into the input
    This function will be called when a code is scanned
$('#code-scan').codeScanner({
    onScan: function ($element, code) {
        console.log(code);
    }
});