/*
* onScan.js - scan-events for hardware barcodes scanners in javascript
*/
var onScan = {
attachTo: function(oDomElement, oOptions) {
if(oDomElement.scannerDetectionData != undefined){
throw new Error("onScan.js is already initialized for DOM element " + oDomElement);
}
var oDefaults = {
onScan: function(sScanned, iQty){}, // Callback after detection of a successfull scanning: function(){sScancode, iCount)}()
onScanError: function(oDebug){}, // Callback after detection of a unsuccessfull scanning (scanned string in parameter)
onKeyProcess: function(sChar, oEvent){}, // Callback after receiving and processing a char (scanned char in parameter)
onKeyDetect: function(iKeyCode, oEvent){}, // Callback after detecting a keyDown (key char in parameter) - in contrast to onKeyProcess, this fires for non-character keys like tab, arrows, etc. too!
onPaste: function(sPasted, oEvent){}, // Callback after receiving a value on paste, no matter if it is a valid code or not
keyCodeMapper: function(oEvent){return String.fromCharCode(oEvent.which)}, // Custom function to decode a keydown event into a character. Must return decoded character or NULL if the given event should not be processed.
onScanButtonLongPress: function(){}, // Callback after detection of a successfull scan while the scan button was pressed and held down
scanButtonKeyCode:false, // Key code of the scanner hardware button (if the scanner button a acts as a key itself)
scanButtonLongPressTime:500, // How long (ms) the hardware button should be pressed, until a callback gets executed
timeBeforeScanTest:100, // Wait duration (ms) after keypress event to check if scanning is finished
avgTimeByChar:30, // Average time (ms) between 2 chars. Used to do difference between keyboard typing and scanning
minLength:6, // Minimum length for a scanning
suffixKeyCodes:[9,13], // Chars to remove and means end of scanning
prefixKeyCodes:[], // Chars to remove and means start of scanning
ignoreIfFocusOn:false, // do not handle scans if the currently focused element matches this selector or object
stopPropagation:false, // Stop immediate propagation on keypress event
preventDefault:false, // Prevent default action on keypress event
reactToKeydown:true, // look for scan input in keyboard events
reactToPaste:false, // look for scan input in paste events
singleScanQty: 1 // Quantity of Items put out to onScan in a single scan
}
oOptions = this._mergeOptions(oDefaults, oOptions);
// initializing options and variables on DomElement
oDomElement.scannerDetectionData = {
options: oOptions,
vars:{
firstCharTime: 0,
lastCharTime: 0,
stringWriting: '',
callIsScanner: false,
testTimer: false,
longPressTimeStart: 0,