Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixs simultaneous click and mousemove events fire
Browse files Browse the repository at this point in the history
mfsousa committed Sep 18, 2015
1 parent 2011a2c commit 3a25cc9
Showing 3 changed files with 30 additions and 2 deletions.
16 changes: 15 additions & 1 deletion dist/dragula.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/dragula.min.js
14 changes: 14 additions & 0 deletions dragula.js
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@ function dragula (initialContainers, options) {
var _item; // item being dragged
var _offsetX; // reference x
var _offsetY; // reference y
var _moveX; // reference move x
var _moveY; // reference move y
var _initialSibling; // reference sibling when grabbed
var _currentSibling; // reference sibling now
var _copy; // item used for copying
@@ -63,6 +65,7 @@ function dragula (initialContainers, options) {
var op = remove ? 'remove' : 'add';
touchy(documentElement, op, 'mousedown', grab);
touchy(documentElement, op, 'mouseup', release);
touchy(documentElement, op, 'mousemove', startBecauseMouseMoved);
}

function eventualMovements (remove) {
@@ -88,6 +91,9 @@ function dragula (initialContainers, options) {
}

function grab (e) {
_moveX = e.clientX;
_moveY = e.clientY;

var ignore = (e.which !== 0 && e.which !== 1) || e.metaKey || e.ctrlKey;
if (ignore) {
return; // we only care about honest-to-god left clicks and touch events
@@ -108,6 +114,14 @@ function dragula (initialContainers, options) {
}

function startBecauseMouseMoved (e) {
if ( ! _grabbed) {
return;
}

if (e.clientX === _moveX && e.clientY === _moveY) {
return;
}

var grabbed = _grabbed; // call to end() unsets _grabbed
eventualMovements(true);
movements();

0 comments on commit 3a25cc9

Please sign in to comment.