@@ -828,9 +828,9 @@ function Parvus(userOptions) {
828
828
} ;
829
829
830
830
/**
831
- * Clear drag after touchend event
831
+ * Clear drag after pointerup event
832
832
*
833
- * This function clears the drag state after the touchend event is triggered.
833
+ * This function clears the drag state after the pointerup event is triggered.
834
834
*/
835
835
const clearDrag = ( ) => {
836
836
drag = {
@@ -890,11 +890,10 @@ function Parvus(userOptions) {
890
890
const TOTAL_TRIGGER_ELEMENTS = TRIGGER_ELEMENTS . length ;
891
891
const SLIDER = GROUPS [ activeGroup ] . slider ;
892
892
const SLIDER_ELEMENTS = GROUPS [ activeGroup ] . sliderElements ;
893
- const IS_TOUCH = config . simulateTouch || isTouchDevice ( ) ;
894
893
const IS_DRAGGABLE = SLIDER . classList . contains ( 'parvus__slider--is-draggable' ) ;
895
894
896
895
// Add draggable class if neccesary
897
- if ( IS_TOUCH && config . swipeClose && ! IS_DRAGGABLE || IS_TOUCH && TOTAL_TRIGGER_ELEMENTS > 1 && ! IS_DRAGGABLE ) {
896
+ if ( config . swipeClose && ! IS_DRAGGABLE || TOTAL_TRIGGER_ELEMENTS > 1 && ! IS_DRAGGABLE ) {
898
897
SLIDER . classList . add ( 'parvus__slider--is-draggable' ) ;
899
898
} else {
900
899
SLIDER . classList . remove ( 'parvus__slider--is-draggable' ) ;
@@ -1061,16 +1060,19 @@ function Parvus(userOptions) {
1061
1060
} ;
1062
1061
1063
1062
/**
1064
- * Event handler for the mousedown event.
1063
+ * Event handler for the pointerdown event.
1065
1064
*
1066
- * This function is called when the mouse button is pressed down .
1067
- * It handles the necessary actions and logic related to the mousedown event.
1065
+ * This function is triggered when a pointer becomes active buttons state .
1066
+ * It handles the necessary actions and logic related to the pointerdown event.
1068
1067
*
1069
- * @param {Event } event - The mousedown event object
1068
+ * @param {Event } event - The pointerdown event object
1070
1069
*/
1071
- const mousedownHandler = event => {
1070
+ const pointerdownHandler = event => {
1072
1071
event . preventDefault ( ) ;
1073
1072
event . stopPropagation ( ) ;
1073
+ if ( event . pointerType === 'mouse' && ! config . simulateTouch ) {
1074
+ return ;
1075
+ }
1074
1076
isDraggingX = false ;
1075
1077
isDraggingY = false ;
1076
1078
pointerDown = true ;
@@ -1089,14 +1091,14 @@ function Parvus(userOptions) {
1089
1091
} ;
1090
1092
1091
1093
/**
1092
- * Event handler for the mousemove event.
1094
+ * Event handler for the pointermove event.
1093
1095
*
1094
- * This function is called when the mouse is moved .
1095
- * It handles the necessary actions and logic related to the mousemove event.
1096
+ * This function is triggered when a pointer changes coordinates .
1097
+ * It handles the necessary actions and logic related to the pointermove event.
1096
1098
*
1097
- * @param {Event } event - The mousemove event object
1099
+ * @param {Event } event - The pointermove event object
1098
1100
*/
1099
- const mousemoveHandler = event => {
1101
+ const pointermoveHandler = event => {
1100
1102
event . preventDefault ( ) ;
1101
1103
if ( pointerDown ) {
1102
1104
const {
@@ -1110,79 +1112,16 @@ function Parvus(userOptions) {
1110
1112
} ;
1111
1113
1112
1114
/**
1113
- * Event handler for the mouseup event.
1114
- *
1115
- * This function is called when a mouse button is released.
1116
- * It handles the necessary actions and logic related to the mouseup event.
1117
- */
1118
- const mouseupHandler = event => {
1119
- event . stopPropagation ( ) ;
1120
- pointerDown = false ;
1121
- const {
1122
- slider
1123
- } = GROUPS [ activeGroup ] ;
1124
- slider . classList . remove ( 'parvus__slider--is-dragging' ) ;
1125
- slider . style . willChange = '' ;
1126
- if ( drag . endX || drag . endY ) {
1127
- updateAfterDrag ( ) ;
1128
- }
1129
- clearDrag ( ) ;
1130
- } ;
1131
-
1132
- /**
1133
- * Event handler for the touchstart event.
1134
- *
1135
- * This function is called when a touch interaction begins.
1136
- * It handles the necessary actions and logic related to the touchstart event.
1137
- *
1138
- * @param {Event } event - The touchstart event object
1139
- */
1140
- const touchstartHandler = event => {
1141
- event . stopPropagation ( ) ;
1142
- isDraggingX = false ;
1143
- isDraggingY = false ;
1144
- const {
1145
- clientX,
1146
- clientY
1147
- } = event . changedTouches [ 0 ] ;
1148
- drag . startX = parseInt ( clientX , 10 ) ;
1149
- drag . startY = parseInt ( clientY , 10 ) ;
1150
- const {
1151
- slider
1152
- } = GROUPS [ activeGroup ] ;
1153
- slider . classList . add ( 'parvus__slider--is-dragging' ) ;
1154
- slider . style . willChange = 'transform' ;
1155
- lightboxOverlayOpacity = getComputedStyle ( lightboxOverlay ) . opacity ;
1156
- } ;
1157
-
1158
- /**
1159
- * Event handler for the touchmove event.
1115
+ * Event handler for the pointerup event.
1160
1116
*
1161
- * This function is called when the touch position changes during a touch interaction .
1162
- * It handles the necessary actions and logic related to the touchmove event.
1117
+ * This function is triggered when a pointer is no longer active buttons state .
1118
+ * It handles the necessary actions and logic related to the pointerup event.
1163
1119
*
1164
- * @param {Event } event - The touchmove event object
1120
+ * @param {Event } event - The pointerup event object
1165
1121
*/
1166
- const touchmoveHandler = event => {
1167
- event . preventDefault ( ) ;
1168
- event . stopPropagation ( ) ;
1169
- const {
1170
- clientX,
1171
- clientY
1172
- } = event . changedTouches [ 0 ] ;
1173
- drag . endX = parseInt ( clientX , 10 ) ;
1174
- drag . endY = parseInt ( clientY , 10 ) ;
1175
- doSwipe ( ) ;
1176
- } ;
1177
-
1178
- /**
1179
- * Event handler for the touchend event.
1180
- *
1181
- * This function is called when the touch interaction ends. It handles the necessary
1182
- * actions and logic related to the touchend event.
1183
- */
1184
- const touchendHandler = event => {
1122
+ const pointerupHandler = event => {
1185
1123
event . stopPropagation ( ) ;
1124
+ pointerDown = false ;
1186
1125
const {
1187
1126
slider
1188
1127
} = GROUPS [ activeGroup ] ;
@@ -1244,19 +1183,10 @@ function Parvus(userOptions) {
1244
1183
// Click event
1245
1184
lightbox . addEventListener ( 'click' , clickHandler ) ;
1246
1185
1247
- // Touch events
1248
- if ( isTouchDevice ( ) ) {
1249
- lightbox . addEventListener ( 'touchstart' , touchstartHandler ) ;
1250
- lightbox . addEventListener ( 'touchmove' , touchmoveHandler ) ;
1251
- lightbox . addEventListener ( 'touchend' , touchendHandler ) ;
1252
- }
1253
-
1254
- // Mouse events
1255
- if ( config . simulateTouch ) {
1256
- lightbox . addEventListener ( 'mousedown' , mousedownHandler ) ;
1257
- lightbox . addEventListener ( 'mouseup' , mouseupHandler ) ;
1258
- lightbox . addEventListener ( 'mousemove' , mousemoveHandler ) ;
1259
- }
1186
+ // Pointer events
1187
+ lightbox . addEventListener ( 'pointerdown' , pointerdownHandler ) ;
1188
+ lightbox . addEventListener ( 'pointerup' , pointerupHandler ) ;
1189
+ lightbox . addEventListener ( 'pointermove' , pointermoveHandler ) ;
1260
1190
} ;
1261
1191
1262
1192
/**
@@ -1276,19 +1206,10 @@ function Parvus(userOptions) {
1276
1206
// Click event
1277
1207
lightbox . removeEventListener ( 'click' , clickHandler ) ;
1278
1208
1279
- // Touch events
1280
- if ( isTouchDevice ( ) ) {
1281
- lightbox . removeEventListener ( 'touchstart' , touchstartHandler ) ;
1282
- lightbox . removeEventListener ( 'touchmove' , touchmoveHandler ) ;
1283
- lightbox . removeEventListener ( 'touchend' , touchendHandler ) ;
1284
- }
1285
-
1286
- // Mouse events
1287
- if ( config . simulateTouch ) {
1288
- lightbox . removeEventListener ( 'mousedown' , mousedownHandler ) ;
1289
- lightbox . removeEventListener ( 'mouseup' , mouseupHandler ) ;
1290
- lightbox . removeEventListener ( 'mousemove' , mousemoveHandler ) ;
1291
- }
1209
+ // Pointer events
1210
+ lightbox . removeEventListener ( 'pointerdown' , pointerdownHandler ) ;
1211
+ lightbox . removeEventListener ( 'pointerup' , pointerupHandler ) ;
1212
+ lightbox . removeEventListener ( 'pointermove' , pointermoveHandler ) ;
1292
1213
} ;
1293
1214
1294
1215
/**
@@ -1319,15 +1240,6 @@ function Parvus(userOptions) {
1319
1240
return lightbox . hasAttribute ( 'open' ) ;
1320
1241
} ;
1321
1242
1322
- /**
1323
- * Check if the device supports touch events
1324
- *
1325
- * @returns {boolean } - True if the device is touch capable, otherwise false
1326
- */
1327
- const isTouchDevice = ( ) => {
1328
- return 'ontouchstart' in window ;
1329
- } ;
1330
-
1331
1243
/**
1332
1244
* Get the current index
1333
1245
*
0 commit comments