GithubHelp home page GithubHelp logo

jquery.scanner.js's Introduction

jquery.scanner.js

a nifty barcode scanning framework (MIT Licensed)


This framework is a somewhat different from other JS barcode scanning frameworks in that it requires user-specified start and end characters to indicate that a "scan" event, not user keyboard input, is taking place - these prefixes/suffixes must be programmed into the scanner using the manufacturer's provided software. The pattern is designed for an interface which may accept both user input and barcode scans. Barcode scans may have non-barcode (namespacing) infomation appended to the scan strings, such as scanner_id, station_id, allowing multiple scanners to work concurrently within the same browser window (eg: five QC stations arranged around a single data-collection PC). A custom parser function takes care of parsing and stripping scanner meta-data and sending it to the correct place on the UI or server.


Overview

  1. configure your scanner(s) to prefix all scanned data with a character that is unlikely to be keyboard-typed by a user. eg |
  2. initialize the framework with the needed options, including the prefix chosen in step 1 (it will automatically be stripped)
  3. optionally specify a parser for scanned strings which will classify different types of barcodes
  4. catch the scan event which will be triggered and bubble from the focused input or document if none is focused

Initialization

// all options with defaults
$.scanner({
	startKey: "|",                               // default scan-start indicator
	endKey: "\r",                                // default scan-end indicator
	parser: function(scanStr){return scanStr;},  // default basic parser. returned data will be passed to "scan" event's handlers
	scanBeep: null,                              // path to an optional scan beep sound to play via HTML5 audio (if present)
	preventOutput: true                          // default behavior is to prevent output of scans
});

Usage

// define a more complex parser and classifier
// scan string formats handled: 10_12345, 10_123456
function complexParser(scanStr) {
	var data = {
		_raw: scanStr,
		class: null,
		scanner_id: scanStr.slice(0,2),		// 2 digit scanner id prefix
		barcode: scanStr.slice(3)			// scanned barcode
	};
	
	// classify barcode type, 5-digit are serial numbers, 6-digit are order numbers
	data.class = data.barcode.length == 5 ? "serial" : data.barcode.length == 6 ? "order" : null;
	
	return data;
}

$.scanner({
	parser: complexParser
});

// bind handler for scanned/parsed data
$(document).bind("scan", function(e, data){
	console.log(data._raw);
	console.log(data.class);
	console.log(data.scanner_id);
	console.log(data.barcode);
});

TODO

  • some way to trigger app-level success/fail beeps based on valid parsing and acceptance of scanned barcodes into various scan contexts or containers. for now this has to be done in "scan" event handlers. meh.

jquery.scanner.js's People

Contributors

leeoniya avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.