Skip to content

Commit c0e3d2c

Browse files
committed
Tidy InteractEvent a little
1 parent a500a60 commit c0e3d2c

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

interact.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,10 +1393,12 @@
13931393
var client,
13941394
page,
13951395
deltaSource = (target && target.options || defaultOptions).deltaSource,
1396-
sourceX = deltaSource + 'X',
1397-
sourceY = deltaSource + 'Y',
1398-
options = target? target.options: defaultOptions,
1399-
origin = getOriginXY(target, element);
1396+
sourceX = deltaSource + 'X',
1397+
sourceY = deltaSource + 'Y',
1398+
options = target? target.options: defaultOptions,
1399+
origin = getOriginXY(target, element),
1400+
starting = phase === 'start',
1401+
ending = phase === 'end';
14001402

14011403
element = element || target._element;
14021404

@@ -1417,7 +1419,7 @@
14171419
client.x -= origin.x;
14181420
client.y -= origin.y;
14191421

1420-
if (checkSnap(target) && !(phase === 'start' && options.snap.elementOrigin)) {
1422+
if (checkSnap(target) && !(starting && options.snap.elementOrigin)) {
14211423

14221424
this.snap = {
14231425
range : snapStatus.range,
@@ -1439,7 +1441,7 @@
14391441
}
14401442
}
14411443

1442-
if (checkRestrict(target) && !(phase === 'start' && options.restrict.elementRect) && restrictStatus.restricted) {
1444+
if (checkRestrict(target) && !(starting && options.restrict.elementRect) && restrictStatus.restricted) {
14431445
page.x += restrictStatus.dx;
14441446
page.y += restrictStatus.dy;
14451447
client.x += restrictStatus.dx;
@@ -1456,7 +1458,7 @@
14561458
this.clientX = client.x;
14571459
this.clientY = client.y;
14581460

1459-
if (phase === 'start' && !(event instanceof InteractEvent)) {
1461+
if (starting && !(event instanceof InteractEvent)) {
14601462
setEventXY(startCoords, this);
14611463
}
14621464

@@ -1484,7 +1486,7 @@
14841486
}
14851487

14861488
// end event dx, dy is difference between start and end points
1487-
if (phase === 'end' || action === 'drop') {
1489+
if (ending || action === 'drop') {
14881490
if (deltaSource === 'client') {
14891491
this.dx = client.x - startCoords.clientX;
14901492
this.dy = client.y - startCoords.clientY;
@@ -1544,15 +1546,15 @@
15441546
? [pointerMoves[0], pointerMoves[1]]
15451547
: event.touches);
15461548

1547-
if (phase === 'start') {
1549+
if (starting) {
15481550
this.distance = touchDistance(pointerMoves);
15491551
this.box = touchBBox(pointerMoves);
15501552
this.scale = 1;
15511553
this.ds = 0;
15521554
this.angle = touchAngle(pointerMoves);
15531555
this.da = 0;
15541556
}
1555-
else if (phase === 'end' || event instanceof InteractEvent) {
1557+
else if (ending || event instanceof InteractEvent) {
15561558
this.distance = prevEvent.distance;
15571559
this.box = prevEvent.box;
15581560
this.scale = prevEvent.scale;
@@ -1571,7 +1573,7 @@
15711573
}
15721574
}
15731575

1574-
if (phase === 'start') {
1576+
if (starting) {
15751577
this.timeStamp = downTime;
15761578
this.dt = 0;
15771579
this.duration = 0;
@@ -1597,12 +1599,12 @@
15971599
// Use natural event coordinates (without snapping/restricions)
15981600
// subtract modifications from previous event if event given is
15991601
// not a native event
1600-
if (phase === 'end' || event instanceof InteractEvent) {
1602+
if (ending || event instanceof InteractEvent) {
16011603
// change in time in seconds
16021604
// use event sequence duration for end events
16031605
// => average speed of the event sequence
16041606
// (minimum dt of 1ms)
1605-
dt = Math.max((phase === 'end'? this.duration: this.dt) / 1000, 0.001);
1607+
dt = Math.max((ending? this.duration: this.dt) / 1000, 0.001);
16061608
dx = this[sourceX] - prevEvent[sourceX];
16071609
dy = this[sourceY] - prevEvent[sourceY];
16081610

@@ -1639,7 +1641,7 @@
16391641
}
16401642
}
16411643

1642-
if ((phase === 'end' || phase === 'inertiastart')
1644+
if ((ending || phase === 'inertiastart')
16431645
&& prevEvent.speed > 600 && this.timeStamp - prevEvent.timeStamp < 150) {
16441646

16451647
var angle = 180 * Math.atan2(prevEvent.velocityY, prevEvent.velocityX) / Math.PI,

0 commit comments

Comments
 (0)