Skip to content

Commit f958b9b

Browse files
authored
Merge pull request #109 from cahva/fix-destroy
Correctly remove mouse-event listeners on destroy
2 parents 278db6e + 8fc20f2 commit f958b9b

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

dist/angularjs-color-picker.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Copyright 2016 ruhley
66
*
7-
* 2016-09-07 13:57:48
7+
* 2016-09-07 15:01:47
88
*
99
*/
1010

@@ -225,6 +225,11 @@ var AngularColorPickerController = function () {
225225
var _android_version = window.navigator.userAgent.match(/Android\s([0-9\.]*)/i);
226226
this.android_version = _android_version && _android_version.length > 1 ? parseFloat(_android_version[1]) : NaN;
227227

228+
var mouseEventHandlers = {
229+
down: this.onMouseDown.bind(this),
230+
up: this.onMouseUp.bind(this),
231+
move: this.onMouseMove.bind(this)
232+
};
228233
// needed variables
229234
this.updateModel = true;
230235

@@ -265,13 +270,13 @@ var AngularColorPickerController = function () {
265270
//---------------------------
266271

267272
this.$scope.$on('$destroy', function () {
268-
_this4.$document.off('mousedown', _this4.onMouseDown);
269-
_this4.$document.off('mouseup', _this4.onMouseUp);
270-
_this4.$document.off('mousemove', _this4.onMouseMove);
273+
_this4.$document.off('mousedown', mouseEventHandlers.down);
274+
_this4.$document.off('mouseup', mouseEventHandlers.up);
275+
_this4.$document.off('mousemove', mouseEventHandlers.move);
271276

272-
_this4.$document.off('touchstart', _this4.onMouseDown);
273-
_this4.$document.off('touchend', _this4.onMouseUp);
274-
_this4.$document.off('touchmove', _this4.onMouseMove);
277+
_this4.$document.off('touchstart', mouseEventHandlers.down);
278+
_this4.$document.off('touchend', mouseEventHandlers.up);
279+
_this4.$document.off('touchmove', mouseEventHandlers.move);
275280

276281
_this4.eventApiDispatch('onDestroy');
277282
});
@@ -280,9 +285,9 @@ var AngularColorPickerController = function () {
280285
this.initConfig();
281286

282287
// setup mouse events
283-
this.$document.on('mousedown', this.onMouseDown.bind(this));
284-
this.$document.on('mouseup', this.onMouseUp.bind(this));
285-
this.$document.on('mousemove', this.onMouseMove.bind(this));
288+
this.$document.on('mousedown', mouseEventHandlers.down);
289+
this.$document.on('mouseup', mouseEventHandlers.up);
290+
this.$document.on('mousemove', mouseEventHandlers.move);
286291

287292
// setup touch events
288293
this.$document.on('touchstart', this.onMouseDown.bind(this));

0 commit comments

Comments
 (0)