Skip to content

Commit 62a8c45

Browse files
authored
Merge pull request #15 from SebouChu/master
Fix draggable during mobile scrolling
2 parents defa149 + c1817d4 commit 62a8c45

File tree

1 file changed

+37
-34
lines changed

1 file changed

+37
-34
lines changed

jquery.ui.touch-punch.js

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*!
2-
* jQuery UI Touch Punch 1.0.6 as modified by RWAP Software
2+
* jQuery UI Touch Punch 1.0.7 as modified by RWAP Software
33
* based on original touchpunch v0.2.3 which has not been updated since 2014
44
*
55
* Updates by RWAP Software to take account of various suggested changes on the original code issues
66
*
77
* Original: https://github.com/furf/jquery-ui-touch-punch
88
* Copyright 2011–2014, Dave Furfero
99
* Dual licensed under the MIT or GPL Version 2 licenses.
10-
*
10+
*
1111
* Fork: https://github.com/RWAP/jquery-ui-touch-punch
1212
*
1313
* Depends:
@@ -28,13 +28,13 @@
2828
}(function ($) {
2929

3030
// Detect touch support
31-
$.support.touch = ( 'ontouchstart' in document
32-
|| 'ontouchstart' in window
33-
|| window.TouchEvent
34-
|| (window.DocumentTouch && document instanceof DocumentTouch)
35-
|| navigator.maxTouchPoints > 0
31+
$.support.touch = ( 'ontouchstart' in document
32+
|| 'ontouchstart' in window
33+
|| window.TouchEvent
34+
|| (window.DocumentTouch && document instanceof DocumentTouch)
35+
|| navigator.maxTouchPoints > 0
3636
|| navigator.msMaxTouchPoints > 0
37-
);
37+
);
3838

3939
// Ignore browsers without touch or mouse support
4040
if (!$.support.touch || !$.ui.mouse) {
@@ -45,7 +45,7 @@
4545
_mouseInit = mouseProto._mouseInit,
4646
_mouseDestroy = mouseProto._mouseDestroy,
4747
touchHandled;
48-
48+
4949
/**
5050
* Get the x,y position of a touch event
5151
* @param {Object} event A touch event
@@ -55,7 +55,7 @@
5555
x: event.originalEvent.changedTouches[0].pageX,
5656
y: event.originalEvent.changedTouches[0].pageY
5757
};
58-
}
58+
}
5959

6060
/**
6161
* Simulate a mouse event based on a corresponding touch event
@@ -69,28 +69,31 @@
6969
return;
7070
}
7171

72-
event.preventDefault();
72+
// Prevent "Ignored attempt to cancel a touchmove event with cancelable=false" errors
73+
if (event.cancelable) {
74+
event.preventDefault();
75+
}
7376

7477
var touch = event.originalEvent.changedTouches[0],
7578
simulatedEvent = document.createEvent('MouseEvents');
76-
79+
7780
// Initialize the simulated mouse event using the touch event's coordinates
7881
simulatedEvent.initMouseEvent(
7982
simulatedType, // type
80-
true, // bubbles
81-
true, // cancelable
82-
window, // view
83-
1, // detail
84-
touch.screenX, // screenX
85-
touch.screenY, // screenY
83+
true, // bubbles
84+
true, // cancelable
85+
window, // view
86+
1, // detail
87+
touch.screenX, // screenX
88+
touch.screenY, // screenY
8689
touch.clientX, // clientX
8790
touch.clientY, // clientY
88-
false, // ctrlKey
89-
false, // altKey
90-
false, // shiftKey
91-
false, // metaKey
92-
0, // button
93-
null // relatedTarget
91+
false, // ctrlKey
92+
false, // altKey
93+
false, // shiftKey
94+
false, // metaKey
95+
0, // button
96+
null // relatedTarget
9497
);
9598

9699
// Dispatch the simulated event to the target element
@@ -104,12 +107,12 @@
104107
mouseProto._touchStart = function (event) {
105108

106109
var self = this;
107-
110+
108111
// Interaction time
109-
this._startedMove = event.timeStamp;
110-
112+
this._startedMove = event.timeStamp;
113+
111114
// Track movement to determine if interaction was a click
112-
self._startPos = getTouchCoords(event);
115+
self._startPos = getTouchCoords(event);
113116

114117
// Ignore the event if another widget is already being handled
115118
if (touchHandled || !self._mouseCapture(event.originalEvent.changedTouches[0])) {
@@ -118,9 +121,9 @@
118121

119122
// Set the flag to prevent other widgets from inheriting the touch event
120123
touchHandled = true;
121-
124+
122125
// Track movement to determine if interaction was a click
123-
self._touchMoved = false;
126+
self._touchMoved = false;
124127

125128
// Simulate the mouseover event
126129
simulateMouseEvent(event, 'mouseover');
@@ -185,9 +188,9 @@
185188
}
186189
}
187190
}
188-
191+
189192
// Unset the flag to determine the touch movement stopped
190-
this._touchMoved = false;
193+
this._touchMoved = false;
191194

192195
// Unset the flag to allow other widgets to inherit the touch event
193196
touchHandled = false;
@@ -200,7 +203,7 @@
200203
* original mouse event handling methods.
201204
*/
202205
mouseProto._mouseInit = function () {
203-
206+
204207
var self = this;
205208

206209
// Delegate the touch handlers to the widget's element
@@ -218,7 +221,7 @@
218221
* Remove the touch event handlers
219222
*/
220223
mouseProto._mouseDestroy = function () {
221-
224+
222225
var self = this;
223226

224227
// Delegate the touch handlers to the widget's element

0 commit comments

Comments
 (0)