Skip to content

Commit

Permalink
readme update
Browse files Browse the repository at this point in the history
  • Loading branch information
Borvik committed Feb 4, 2017
1 parent c7ff4e1 commit e1a2cc4
Showing 1 changed file with 42 additions and 24 deletions.
66 changes: 42 additions & 24 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
Basic Usage:
# jquery-inputreader

$('#testInput').inputreader('listen').on('inputreader:scan', function(e) {
if (e.scandata == '12') {
jquery-inputreader is a small library to allow batch scanning of whole barcodes or magnetic stripes from keyboard based readers. The basic principal behind these readers is that they emulate a keyboard - but they type much faster than any human would.

This library traps all keystrokes, and if the timeout passes, then the scan is done and an event is raised. During the event, if the pattern of the scan data matches a pattern you define, you can prevent the default action - which is to insert it into the current input box.

*NOTE:* This library will prevent the normal keypress/keyup behavior.

Because the default action is to insert the data at the cursor in the input box, it is best to listen for reading on the input box. However, you may also listen on other elements as well (such as *document*) though that would suppress keyevents for a broader scope.

## Options
`$.fn.inputreader.defaults.timeout`: Specifies the timeout between keypresses (default is 50 milliseconds).

`$.fn.inputreader.defaults.insertText`: Allow/disallow inserting the text after the event (default is true)
- preventDefault() suppersedes this.
- also the element must support the selectionStart property as well

## Parameters
- `listen` - starts listening
- `stop` - stops listening

## Events

`inputreader:scan`

This event is raised when the timeout between keys is reached. The default timeout of 50 milliseconds should be almost imperceptible to normal typing speeds.

Normal keypresses **_WILL_** trigger this event.

The scanned data (or key pressed) can be found in the `scandata` property of the event.

To prevent insertion used `preventDefault()`.

## Basic Usage

```
$('#testInput')
.inputreader('listen')
.on('inputreader:scan', function(e) {
if (e.scandata == '12') { // your pattern here
e.preventDefault();
}
});
Listens for keydown on the selected elements.

Parameters for .inputreader():
listen - starts listening
stop - stops listening

One Event - 'inputreader:scan'
Raised when timeout between keys is reached (default is 50 milliseconds)
- 50 should be almost imperciptible to normal typing speeds, but barcode scanners and magnetic stripe readers
- type much faster so they should be caught.
Normal key presses DO trigger this event
Normal key events keypress and keyup will not function on the element while listening.
Data scanned (or the keypress) can be found in scandata.
To prevent insertion use preventDefault()

Options:
$.fn.inputreader.defaults.timeout: Specify the timeout between keypresses (default is 50 milliseconds)
$.fn.inputreader.defaults.insertText: Allow/disallow inserting the text after the event (default is true)
- preventDefault() suppersedes this.
- also the element must support the selectionStart property as well
});
```

0 comments on commit e1a2cc4

Please sign in to comment.