From 61799344afe57f655efaedfa16a35cb131cd7e40 Mon Sep 17 00:00:00 2001 From: Florian Sellmayr Date: Wed, 8 Jul 2015 14:18:45 +0200 Subject: [PATCH 1/2] fix issue with click-events being prevented when a device sends mouse-move events along with the click --- spec/eventsSpec.js | 26 ++++++++++++++++++++++++++ src/dragdealer.js | 5 +++++ 2 files changed, 31 insertions(+) diff --git a/spec/eventsSpec.js b/spec/eventsSpec.js index 79af24b..e4d236c 100644 --- a/spec/eventsSpec.js +++ b/spec/eventsSpec.js @@ -37,6 +37,32 @@ describe("Click events inside handle", function() { expect(clickHandler.calls.length).toEqual(1); expect(clickHandler.calls[0].args[0].isDefaultPrevented()).toBe(false); }); + + it("should be passed through if mouse moving without changing position", function() { + var clickHandler = jasmine.createSpy(); + var someX = 42; + var someY = 42; + helpers.initDragdealer('content-slider'); + + var wrapperPosition = $('#content-slider').offset(); + + $('#content-slider').click(clickHandler); + $('#content-slider .inner-button') + .simulate('mousemove',{ // to have a consistent startDrag position + clientX: someX, + clientY: someY + }) + .simulate('mousedown') + .simulate('mousemove',{ + clientX: someX, + clientY: someY + }) + .simulate('mouseup') + .simulate('click'); + + expect(clickHandler.calls.length).toEqual(1); + expect(clickHandler.calls[0].args[0].isDefaultPrevented()).toBe(false); + }); }); describe("Previous DOM events", function() { diff --git a/src/dragdealer.js b/src/dragdealer.js index 38d1c85..1e6f8e5 100644 --- a/src/dragdealer.js +++ b/src/dragdealer.js @@ -415,6 +415,11 @@ Dragdealer.prototype = { this.startDrag(); }, onDocumentMouseMove: function(e) { + if((e.clientX - this.dragStartPosition.x) === 0 && (e.clientY - this.dragStartPosition.y) === 0) { + // This is required on some Windows8 machines that get mouse move events without actual mouse movement + return; + } + Cursor.refresh(e); if (this.dragging) { this.activity = true; From 9f0070751a7718b61a0227cc7436428ff605c390 Mon Sep 17 00:00:00 2001 From: Florian Sellmayr Date: Thu, 9 Jul 2015 09:28:40 +0200 Subject: [PATCH 2/2] improve code style --- src/dragdealer.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dragdealer.js b/src/dragdealer.js index 1e6f8e5..afc5c79 100644 --- a/src/dragdealer.js +++ b/src/dragdealer.js @@ -415,7 +415,8 @@ Dragdealer.prototype = { this.startDrag(); }, onDocumentMouseMove: function(e) { - if((e.clientX - this.dragStartPosition.x) === 0 && (e.clientY - this.dragStartPosition.y) === 0) { + if ((e.clientX - this.dragStartPosition.x) === 0 && + (e.clientY - this.dragStartPosition.y) === 0) { // This is required on some Windows8 machines that get mouse move events without actual mouse movement return; }