|
1091 | 1091 | * - DOM event object
|
1092 | 1092 | */
|
1093 | 1093 | var onTouchStart = function(e) {
|
| 1094 | + // watch only for left mouse, touch contact and pen contact |
| 1095 | + // touchstart event object doesn`t have button property |
| 1096 | + if (e.type !== 'touchstart' && e.button !== 0) { |
| 1097 | + return; |
| 1098 | + } |
| 1099 | + e.preventDefault(); |
1094 | 1100 | //disable slider controls while user is interacting with slides to avoid slider freeze that happens on touch devices when a slide swipe happens immediately after interacting with slider controls
|
1095 | 1101 | slider.controls.el.addClass('disabled');
|
1096 | 1102 |
|
1097 | 1103 | if (slider.working) {
|
1098 |
| - e.preventDefault(); |
1099 | 1104 | slider.controls.el.removeClass('disabled');
|
1100 | 1105 | } else {
|
1101 | 1106 | // record the original position when touch starts
|
|
1110 | 1115 | slider.pointerId = orig.pointerId;
|
1111 | 1116 | slider.viewport.get(0).setPointerCapture(slider.pointerId);
|
1112 | 1117 | }
|
| 1118 | + // store original event data for click fixation |
| 1119 | + slider.originalClickTarget = orig.originalTarget; |
| 1120 | + slider.originalClickButton = orig.button; |
| 1121 | + slider.originalClickButtons = orig.buttons; |
| 1122 | + slider.originalEventType = orig.type; |
| 1123 | + // at this moment we don`t know what it is click or swipe |
| 1124 | + slider.hasMove = false; |
1113 | 1125 | // bind a "touchmove" event to the viewport
|
1114 | 1126 | slider.viewport.bind('touchmove MSPointerMove pointermove', onTouchMove);
|
1115 | 1127 | // bind a "touchend" event to the viewport
|
|
1125 | 1137 | * - DOM event object
|
1126 | 1138 | */
|
1127 | 1139 | var onPointerCancel = function(e) {
|
| 1140 | + e.preventDefault(); |
1128 | 1141 | /* onPointerCancel handler is needed to deal with situations when a touchend
|
1129 | 1142 | doesn't fire after a touchstart (this happens on windows phones only) */
|
1130 | 1143 | setPositionProperty(slider.touch.originalPos.left, 'reset', 0);
|
|
1153 | 1166 | yMovement = Math.abs(touchPoints[0].pageY - slider.touch.start.y),
|
1154 | 1167 | value = 0,
|
1155 | 1168 | change = 0;
|
| 1169 | + // this is swipe |
| 1170 | + slider.hasMove = true; |
1156 | 1171 |
|
1157 | 1172 | // x axis swipe
|
1158 | 1173 | if ((xMovement * 3) > yMovement && slider.settings.preventDefaultSwipeX) {
|
|
1161 | 1176 | } else if ((yMovement * 3) > xMovement && slider.settings.preventDefaultSwipeY) {
|
1162 | 1177 | e.preventDefault();
|
1163 | 1178 | }
|
| 1179 | + if (e.type !== 'touchmove') { |
| 1180 | + e.preventDefault(); |
| 1181 | + } |
| 1182 | + |
1164 | 1183 | if (slider.settings.mode !== 'fade' && slider.settings.oneToOneTouch) {
|
1165 | 1184 | // if horizontal, drag along x axis
|
1166 | 1185 | if (slider.settings.mode === 'horizontal') {
|
|
1182 | 1201 | * - DOM event object
|
1183 | 1202 | */
|
1184 | 1203 | var onTouchEnd = function(e) {
|
| 1204 | + e.preventDefault(); |
1185 | 1205 | slider.viewport.unbind('touchmove MSPointerMove pointermove', onTouchMove);
|
1186 | 1206 | //enable slider controls as soon as user stops interacing with slides
|
1187 | 1207 | slider.controls.el.removeClass('disabled');
|
|
1232 | 1252 | }
|
1233 | 1253 | }
|
1234 | 1254 | slider.viewport.unbind('touchend MSPointerUp pointerup', onTouchEnd);
|
| 1255 | + |
1235 | 1256 | if (slider.viewport.get(0).releasePointerCapture) {
|
1236 | 1257 | slider.viewport.get(0).releasePointerCapture(slider.pointerId);
|
1237 | 1258 | }
|
| 1259 | + // if slider had swipe with left mouse, touch contact and pen contact |
| 1260 | + if (slider.hasMove === false && (slider.originalClickButton === 0 || slider.originalEventType === 'touchstart')) { |
| 1261 | + // trigger click event (fix for Firefox59 and PointerEvent standard compatibility) |
| 1262 | + $(slider.originalClickTarget).trigger({ |
| 1263 | + type: 'click', |
| 1264 | + button: slider.originalClickButton, |
| 1265 | + buttons: slider.originalClickButtons |
| 1266 | + }); |
| 1267 | + } |
1238 | 1268 | };
|
1239 | 1269 |
|
1240 | 1270 | /**
|
|
0 commit comments