Skip to content

Commit

Permalink
fix: manual click event trigger as the card was detached from DOM dur…
Browse files Browse the repository at this point in the history
…ing dragging (#133)
  • Loading branch information
adelura authored and gajus committed Sep 3, 2018
1 parent 45b5787 commit 9a19ea2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
coverage
dist
node_modules
package-lock.json
*.log
.*
!.README
Expand Down
12 changes: 11 additions & 1 deletion src/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const Card = (stack, targetElement, prepend) => {
let throwDirectionToEventName;
let throwOutDistance;
let throwWhere;
let appendedDuringMouseDown;

const construct = () => {
card = {};
Expand Down Expand Up @@ -194,10 +195,16 @@ const Card = (stack, targetElement, prepend) => {
})();
} else {
targetElement.addEventListener('mousedown', () => {
appendedDuringMouseDown = Card.appendToParent(targetElement) || appendedDuringMouseDown;
eventEmitter.trigger('panstart');
});

targetElement.addEventListener('mouseup', () => {
if (appendedDuringMouseDown) {
targetElement.click();
appendedDuringMouseDown = false;
}

if (isDraging && !isPanning) {
eventEmitter.trigger('dragend', {
target: targetElement
Expand Down Expand Up @@ -453,11 +460,14 @@ Card.appendToParent = (element) => {
const parentNode = element.parentNode;
const siblings = elementChildren(parentNode);
const targetIndex = siblings.indexOf(element);
const appended = targetIndex + 1 !== siblings.length;

if (targetIndex + 1 !== siblings.length) {
if (appended) {
parentNode.removeChild(element);
parentNode.appendChild(element);
}

return appended;
};

/**
Expand Down

0 comments on commit 9a19ea2

Please sign in to comment.