Glideh / jquery-code-scanner

Lightweight handheld code scanner detector
31 stars 16 forks source link
jquery

jQuery Code Scanner

The aim here is to be able to get a scanned 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.

Installation

$ bower install jquery-code-scanner

Usage

Include the tool

<script src="https://github.com/Glideh/jquery-code-scanner/raw/master/js/jquery.min.js"></script>
<script src="https://github.com/Glideh/jquery-code-scanner/raw/master/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

$('#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

$('#code-scan').codeScanner({
    onScan: function ($element, code) {
        console.log(code);
    }
});