|
1 | 1 | /*!
|
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 |
3 | 3 | * based on original touchpunch v0.2.3 which has not been updated since 2014
|
4 | 4 | *
|
5 | 5 | * Updates by RWAP Software to take account of various suggested changes on the original code issues
|
6 | 6 | *
|
7 | 7 | * Original: https://github.com/furf/jquery-ui-touch-punch
|
8 | 8 | * Copyright 2011–2014, Dave Furfero
|
9 | 9 | * Dual licensed under the MIT or GPL Version 2 licenses.
|
10 |
| - * |
| 10 | + * |
11 | 11 | * Fork: https://github.com/RWAP/jquery-ui-touch-punch
|
12 | 12 | *
|
13 | 13 | * Depends:
|
|
28 | 28 | }(function ($) {
|
29 | 29 |
|
30 | 30 | // 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 |
36 | 36 | || navigator.msMaxTouchPoints > 0
|
37 |
| - ); |
| 37 | + ); |
38 | 38 |
|
39 | 39 | // Ignore browsers without touch or mouse support
|
40 | 40 | if (!$.support.touch || !$.ui.mouse) {
|
|
45 | 45 | _mouseInit = mouseProto._mouseInit,
|
46 | 46 | _mouseDestroy = mouseProto._mouseDestroy,
|
47 | 47 | touchHandled;
|
48 |
| - |
| 48 | + |
49 | 49 | /**
|
50 | 50 | * Get the x,y position of a touch event
|
51 | 51 | * @param {Object} event A touch event
|
|
55 | 55 | x: event.originalEvent.changedTouches[0].pageX,
|
56 | 56 | y: event.originalEvent.changedTouches[0].pageY
|
57 | 57 | };
|
58 |
| - } |
| 58 | + } |
59 | 59 |
|
60 | 60 | /**
|
61 | 61 | * Simulate a mouse event based on a corresponding touch event
|
|
69 | 69 | return;
|
70 | 70 | }
|
71 | 71 |
|
72 |
| - event.preventDefault(); |
| 72 | + // Prevent "Ignored attempt to cancel a touchmove event with cancelable=false" errors |
| 73 | + if (event.cancelable) { |
| 74 | + event.preventDefault(); |
| 75 | + } |
73 | 76 |
|
74 | 77 | var touch = event.originalEvent.changedTouches[0],
|
75 | 78 | simulatedEvent = document.createEvent('MouseEvents');
|
76 |
| - |
| 79 | + |
77 | 80 | // Initialize the simulated mouse event using the touch event's coordinates
|
78 | 81 | simulatedEvent.initMouseEvent(
|
79 | 82 | 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 |
86 | 89 | touch.clientX, // clientX
|
87 | 90 | 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 |
94 | 97 | );
|
95 | 98 |
|
96 | 99 | // Dispatch the simulated event to the target element
|
|
104 | 107 | mouseProto._touchStart = function (event) {
|
105 | 108 |
|
106 | 109 | var self = this;
|
107 |
| - |
| 110 | + |
108 | 111 | // Interaction time
|
109 |
| - this._startedMove = event.timeStamp; |
110 |
| - |
| 112 | + this._startedMove = event.timeStamp; |
| 113 | + |
111 | 114 | // Track movement to determine if interaction was a click
|
112 |
| - self._startPos = getTouchCoords(event); |
| 115 | + self._startPos = getTouchCoords(event); |
113 | 116 |
|
114 | 117 | // Ignore the event if another widget is already being handled
|
115 | 118 | if (touchHandled || !self._mouseCapture(event.originalEvent.changedTouches[0])) {
|
|
118 | 121 |
|
119 | 122 | // Set the flag to prevent other widgets from inheriting the touch event
|
120 | 123 | touchHandled = true;
|
121 |
| - |
| 124 | + |
122 | 125 | // Track movement to determine if interaction was a click
|
123 |
| - self._touchMoved = false; |
| 126 | + self._touchMoved = false; |
124 | 127 |
|
125 | 128 | // Simulate the mouseover event
|
126 | 129 | simulateMouseEvent(event, 'mouseover');
|
|
185 | 188 | }
|
186 | 189 | }
|
187 | 190 | }
|
188 |
| - |
| 191 | + |
189 | 192 | // Unset the flag to determine the touch movement stopped
|
190 |
| - this._touchMoved = false; |
| 193 | + this._touchMoved = false; |
191 | 194 |
|
192 | 195 | // Unset the flag to allow other widgets to inherit the touch event
|
193 | 196 | touchHandled = false;
|
|
200 | 203 | * original mouse event handling methods.
|
201 | 204 | */
|
202 | 205 | mouseProto._mouseInit = function () {
|
203 |
| - |
| 206 | + |
204 | 207 | var self = this;
|
205 | 208 |
|
206 | 209 | // Delegate the touch handlers to the widget's element
|
|
218 | 221 | * Remove the touch event handlers
|
219 | 222 | */
|
220 | 223 | mouseProto._mouseDestroy = function () {
|
221 |
| - |
| 224 | + |
222 | 225 | var self = this;
|
223 | 226 |
|
224 | 227 | // Delegate the touch handlers to the widget's element
|
|
0 commit comments