summaryrefslogtreecommitdiff
path: root/addons/barcodes/static/src/js/barcode_events.js
diff options
context:
space:
mode:
authorArthur Maniet <arthurmaniet@me.com>2015-07-09 10:36:35 +0200
committerArthur Maniet <arthurmaniet@me.com>2015-07-30 07:55:52 +0200
commit5b01eca5e4ffc2dc453a3a85c9e753236a18d6e7 (patch)
treef1b2679ab8357663567df448b1fcaeb0545501cd /addons/barcodes/static/src/js/barcode_events.js
parentf45904f581edef42a7572101c10359c739b65d55 (diff)
[FIX] barcodes: BarcodeEvents handler binding and unbinding
In order to remove an eventhandler, removeEventListener must receive the same function reference that was passed to addEventListener. So the handlers references are kept as attributes of the class.
Diffstat (limited to 'addons/barcodes/static/src/js/barcode_events.js')
-rw-r--r--addons/barcodes/static/src/js/barcode_events.js16
1 files changed, 10 insertions, 6 deletions
diff --git a/addons/barcodes/static/src/js/barcode_events.js b/addons/barcodes/static/src/js/barcode_events.js
index 55347bf458d..d4306532cb9 100644
--- a/addons/barcodes/static/src/js/barcode_events.js
+++ b/addons/barcodes/static/src/js/barcode_events.js
@@ -14,6 +14,10 @@ var BarcodeEvents = core.Class.extend(mixins.PropertiesMixin, {
init: function(parent) {
mixins.PropertiesMixin.init.call(this);
this.setParent(parent);
+ // Keep a reference of the handler functions to use when adding and removing event listeners
+ this.__keydown_handler = _.bind(this.keydown_handler, this);
+ this.__keyup_handler = _.bind(this.keyup_handler, this);
+ this.__handler = _.bind(this.handler, this);
// Bind event handler once the DOM is loaded
// TODO: find a way to be active only when there are listeners on the bus
$(this.start.bind(this));
@@ -127,15 +131,15 @@ var BarcodeEvents = core.Class.extend(mixins.PropertiesMixin, {
},
start: function(){
- document.body.addEventListener('keydown', this.keydown_handler.bind(this), true);
- document.body.addEventListener('keyup', this.keyup_handler.bind(this), true);
- document.body.addEventListener('keypress', this.handler.bind(this), true);
+ document.body.addEventListener('keypress', this.__handler, true);
+ document.body.addEventListener('keydown', this.__keydown_handler, true);
+ document.body.addEventListener('keyup', this.__keyup_handler, true);
},
stop: function(){
- document.body.removeEventListener('keydown', this.keydown_handler.bind(this), true);
- document.body.removeEventListener('keyup', this.keyup_handler.bind(this), true);
- document.body.removeEventListener('keypress', this.handler.bind(this), true);
+ document.body.removeEventListener('keypress', this.__handler, true);
+ document.body.removeEventListener('keydown', this.__keydown_handler, true);
+ document.body.removeEventListener('keyup', this.__keyup_handler, true);
},
});