diff --git a/CanvasInput.js b/CanvasInput.js index 6df2eeb..14e8add 100644 --- a/CanvasInput.js +++ b/CanvasInput.js @@ -94,21 +94,30 @@ } // setup main canvas events + self._removals = []; if (self._canvas) { - self._canvas.addEventListener('mousemove', function(e) { + var mousemove = function(e) { e = e || window.event; self.mousemove(e, self); - }, false); + }; - self._canvas.addEventListener('mousedown', function(e) { + var mousedown = function(e) { e = e || window.event; self.mousedown(e, self); - }, false); + }; - self._canvas.addEventListener('mouseup', function(e) { + var mouseup = function(e) { e = e || window.event; self.mouseup(e, self); - }, false); + }; + + self._canvas.addEventListener('mousemove', mousemove, false); + self._canvas.addEventListener('mousedown', mousedown, false); + self._canvas.addEventListener('mouseup', mouseup, false); + + self._removals.push([self._canvas, 'mousemove', mousemove, false]); + self._removals.push([self._canvas, 'mousedown', mousedown, false]); + self._removals.push([self._canvas, 'mouseup', mouseup, false]); } // setup a global mouseup to blur the input outside of the canvas @@ -122,6 +131,9 @@ window.addEventListener('mouseup', autoBlur, true); window.addEventListener('touchend', autoBlur, true); + self._removals.push([window, 'mouseup', autoBlur, true]); + self._removals.push([window, 'touchend', autoBlur, true]); + // create the hidden input element self._hiddenInput = document.createElement('input'); self._hiddenInput.type = 'text'; @@ -1208,6 +1220,14 @@ // remove the hidden input box document.body.removeChild(self._hiddenInput); + // remove event listeners + var removals = self._removals; + for (var i=0; i