Skip to content
This repository has been archived by the owner on May 12, 2018. It is now read-only.

Commit

Permalink
Merge pull request bevacqua#207 from mfsousa/master
Browse files Browse the repository at this point in the history
Fixs simultaneous click and mousemove events fire
  • Loading branch information
bevacqua committed Sep 18, 2015
2 parents 2011a2c + 3013502 commit 513cb41
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions dragula.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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();
Expand Down

0 comments on commit 513cb41

Please sign in to comment.