@@ -966,6 +966,8 @@ export default function Tobii (userOptions) {
966
966
const pointermoveHandler = ( event ) => {
967
967
if ( ! pointerDownCache . length ) return
968
968
969
+ groups [ activeGroup ] . slider . classList . add ( 'tobii__slider--is-' + ( isZoomed ( ) ? 'moving' : 'dragging' ) )
970
+
969
971
// Find this event in the cache and update its record with this event
970
972
const index = pointerDownCache . findIndex (
971
973
( cachedEv ) => cachedEv . pointerId === event . pointerId
@@ -1012,8 +1014,6 @@ export default function Tobii (userOptions) {
1012
1014
// Skip animation if drag distance is too low
1013
1015
if ( distance ( deltaX , deltaY ) < 10 ) return
1014
1016
1015
- groups [ activeGroup ] . slider . classList . add ( 'tobii__slider--is-dragging' )
1016
-
1017
1017
if ( Math . abs ( deltaX ) > Math . abs ( deltaY ) && groups [ activeGroup ] . elementsLength > 1 ) {
1018
1018
// Horizontal swipe
1019
1019
groups [ activeGroup ] . slider . style . transform =
@@ -1033,14 +1033,33 @@ export default function Tobii (userOptions) {
1033
1033
const pointerupHandler = ( event ) => {
1034
1034
event . stopPropagation ( )
1035
1035
1036
+ groups [ activeGroup ] . slider . classList . remove ( 'tobii__slider--is-' + ( isZoomed ( ) ? 'moving' : 'dragging' ) )
1037
+
1036
1038
// Remove this event from the target's cache
1037
1039
const index = pointerDownCache . findIndex (
1038
1040
( cachedEv ) => cachedEv . pointerId === event . pointerId
1039
1041
)
1040
1042
pointerDownCache . splice ( index , 1 )
1041
1043
1042
- const isDragging = DRAG . startX !== DRAG . x || DRAG . startY !== DRAG . y
1043
- if ( ! isDragging ) {
1044
+ const MOVEMENT_X = DRAG . startX - DRAG . x
1045
+ const MOVEMENT_Y = DRAG . startY - DRAG . y
1046
+ const MOVEMENT_X_DISTANCE = Math . abs ( MOVEMENT_X )
1047
+ const MOVEMENT_Y_DISTANCE = Math . abs ( MOVEMENT_Y )
1048
+ if ( MOVEMENT_X_DISTANCE || MOVEMENT_Y_DISTANCE ) {
1049
+ if ( ! isZoomed ( ) ) {
1050
+ // Evaluate drag
1051
+ if ( MOVEMENT_X < 0 && MOVEMENT_X_DISTANCE > userSettings . threshold && groups [ activeGroup ] . currentIndex > 0 ) {
1052
+ previous ( )
1053
+ } else if ( MOVEMENT_X > 0 && MOVEMENT_X_DISTANCE > userSettings . threshold &&
1054
+ groups [ activeGroup ] . currentIndex !== groups [ activeGroup ] . elementsLength - 1 ) {
1055
+ next ( )
1056
+ } else if ( MOVEMENT_Y > 0 && MOVEMENT_Y_DISTANCE > userSettings . threshold && userSettings . swipeClose ) {
1057
+ close ( )
1058
+ } else {
1059
+ updateOffset ( )
1060
+ }
1061
+ }
1062
+ } else {
1044
1063
// Evaluate tap
1045
1064
const currentTime = new Date ( ) . getTime ( )
1046
1065
const tapLength = currentTime - lastTapTime
@@ -1069,27 +1088,6 @@ export default function Tobii (userOptions) {
1069
1088
}
1070
1089
}
1071
1090
}
1072
-
1073
- if ( isDragging && ! isZoomed ( ) ) {
1074
- // Evaluate drag
1075
- groups [ activeGroup ] . slider . classList . remove ( 'tobii__slider--is-dragging' )
1076
-
1077
- const MOVEMENT_X = DRAG . startX - DRAG . x
1078
- const MOVEMENT_Y = DRAG . startY - DRAG . y
1079
- const MOVEMENT_X_DISTANCE = Math . abs ( MOVEMENT_X )
1080
- const MOVEMENT_Y_DISTANCE = Math . abs ( MOVEMENT_Y )
1081
-
1082
- if ( MOVEMENT_X < 0 && MOVEMENT_X_DISTANCE > userSettings . threshold && groups [ activeGroup ] . currentIndex > 0 ) {
1083
- previous ( )
1084
- } else if ( MOVEMENT_X > 0 && MOVEMENT_X_DISTANCE > userSettings . threshold &&
1085
- groups [ activeGroup ] . currentIndex !== groups [ activeGroup ] . elementsLength - 1 ) {
1086
- next ( )
1087
- } else if ( MOVEMENT_Y > 0 && MOVEMENT_Y_DISTANCE > userSettings . threshold && userSettings . swipeClose ) {
1088
- close ( )
1089
- } else {
1090
- updateOffset ( )
1091
- }
1092
- }
1093
1091
}
1094
1092
1095
1093
/**
0 commit comments