summaryrefslogtreecommitdiff
path: root/addons/barcodes/static/src/js/barcode_events.js
diff options
context:
space:
mode:
authorArthur Maniet <arthurmaniet@me.com>2015-07-09 11:00:17 +0200
committerArthur Maniet <arthurmaniet@me.com>2015-07-30 07:55:53 +0200
commit0ed6a7dd18eeddaa20ec1c504f5d3400f2baf4dd (patch)
treeb9b98f9b44c1ea68b4a2afa683784350bf3cfbc9 /addons/barcodes/static/src/js/barcode_events.js
parent47262c85872abe100c30dd71b800e5577a6fb8fe (diff)
[IMP] barcodes: use a known terminal char to stops buffering keys
BarcodeEvents uses the fact that a barcode usually ends with \n, \r or \t - and never contains it - to stop buffing keys as soon as such a character is inputted instead of waiting x milliseconds.
Diffstat (limited to 'addons/barcodes/static/src/js/barcode_events.js')
-rw-r--r--addons/barcodes/static/src/js/barcode_events.js12
1 files changed, 10 insertions, 2 deletions
diff --git a/addons/barcodes/static/src/js/barcode_events.js b/addons/barcodes/static/src/js/barcode_events.js
index 96ccb51a1af..73366cc7755 100644
--- a/addons/barcodes/static/src/js/barcode_events.js
+++ b/addons/barcodes/static/src/js/barcode_events.js
@@ -9,7 +9,12 @@ var BarcodeEvents = core.Class.extend(mixins.PropertiesMixin, {
key_pressed: {},
buffered_key_events: [],
min_barcode_keys: 3, // minimum barcode length
- max_time_between_keys_in_ms: 50, // max time between keys to be detected as a barcode
+ // By knowing the terminal character we can interpret buffered keys
+ // as a barcode as soon as it's encountered (instead of waiting x ms)
+ suffix: /[\n\r\t]+/,
+ // Keys from a barcode scanner are usually processed as quick as possible,
+ // but some scanners can use an intercharacter delay (we support <= 50 ms)
+ max_time_between_keys_in_ms: 55,
init: function(parent) {
mixins.PropertiesMixin.init.call(this);
@@ -125,7 +130,10 @@ var BarcodeEvents = core.Class.extend(mixins.PropertiesMixin, {
e.stopImmediatePropagation();
clearTimeout(this.timeout);
- this.timeout = setTimeout(this.handle_buffered_keys.bind(this), this.max_time_between_keys_in_ms);
+ if (String.fromCharCode(e.which).match(this.suffix) !== null)
+ this.handle_buffered_keys();
+ else
+ this.timeout = setTimeout(this.handle_buffered_keys.bind(this), this.max_time_between_keys_in_ms);
}
}
},