Skip to content
This repository was archived by the owner on Aug 24, 2020. It is now read-only.

Commit 06ac4f9

Browse files
feat(#10): fork update swing.js (9a19ea2 from Sep 3, 2018 and 45b5787 Aug 18, 2018)
1 parent e198ffc commit 06ac4f9

File tree

1 file changed

+13
-1
lines changed
  • src/app/modules/ionic-swing/swing

1 file changed

+13
-1
lines changed

src/app/modules/ionic-swing/swing/card.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,14 @@ const appendToParent = (element) => {
6868
const parentNode = element.parentNode;
6969
const siblings = elementChildren(parentNode);
7070
const targetIndex = siblings.indexOf(element);
71+
const appended = targetIndex + 1 !== siblings.length;
7172

72-
if (targetIndex + 1 !== siblings.length) {
73+
if (appended) {
7374
parentNode.removeChild(element);
7475
parentNode.appendChild(element);
7576
}
77+
78+
return appended;
7679
};
7780

7881
/**
@@ -207,6 +210,7 @@ const Card = (stack, targetElement) => {
207210
let throwDirectionToEventName;
208211
let throwOutDistance;
209212
let throwWhere;
213+
let appendedDuringMouseDown;
210214

211215
const construct = () => {
212216
card = {};
@@ -347,10 +351,16 @@ const Card = (stack, targetElement) => {
347351
})();
348352
} else {
349353
targetElement.addEventListener('mousedown', () => {
354+
appendedDuringMouseDown = appendToParent(targetElement) || appendedDuringMouseDown;
350355
eventEmitter.trigger('panstart');
351356
}, { passive: true });
352357

353358
targetElement.addEventListener('mouseup', () => {
359+
if (appendedDuringMouseDown) {
360+
targetElement.click();
361+
appendedDuringMouseDown = false;
362+
}
363+
354364
if (isDraging && !isPanning) {
355365
eventEmitter.trigger('dragend', {
356366
target: targetElement
@@ -473,13 +483,15 @@ const Card = (stack, targetElement) => {
473483
lastThrow.direction = direction || computeDirection(fromX, fromY, config.allowedDirections);
474484

475485
if (where === THROW_IN) {
486+
appendToParent(targetElement);
476487
springThrowIn.setCurrentValue(0).setAtRest().setEndValue(1);
477488

478489
eventEmitter.trigger('throwin', {
479490
target: targetElement,
480491
throwDirection: lastThrow.direction
481492
});
482493
} else if (where === THROW_OUT) {
494+
appendToParent(targetElement);
483495
isDraging = false;
484496
springThrowOut.setCurrentValue(0).setAtRest().setVelocity(100).setEndValue(1);
485497

0 commit comments

Comments
 (0)