Skip to content

Commit 8d3a0a2

Browse files
Fix touch handler binding across multiple widgets and improve msPointer detection (#42)
* Refactor touch-punch to bind handlers per instance and improve msPointer detection * Replace optional chaining in mspointer detection with legacy-safe check to avoid syntax issues on older browsers * Revert auto formatting and restore original formatting style * Restore LF line endings and revert formatting noise
1 parent 3e5928f commit 8d3a0a2

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

jquery.ui.touch-punch.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,6 @@
195195
touchHandled = false;
196196
};
197197

198-
let _touchStartBound;
199-
let _touchMoveBound;
200-
let _touchEndBound
201-
202198
/**
203199
* A duck punch of the $.ui.mouse _mouseInit method to support touch events.
204200
* This method extends the widget with bound touch event handlers that
@@ -210,19 +206,19 @@
210206
let self = this;
211207

212208
// Microsoft Surface Support = remove original touch Action
213-
if ($.support.mspointer) {
209+
if ($.mspointer || ($.support && $.support.mspointer)) {
214210
self.element[0].style.msTouchAction = 'none';
215211
}
216212

217-
_touchStartBound = mouseProto._touchStart.bind(self);
218-
_touchMoveBound = mouseProto._touchMove.bind(self);
219-
_touchEndBound = mouseProto._touchEnd.bind(self);
213+
self._touchStartBound = mouseProto._touchStart.bind(self);
214+
self._touchMoveBound = mouseProto._touchMove.bind(self);
215+
self._touchEndBound = mouseProto._touchEnd.bind(self);
220216

221217
// Delegate the touch handlers to the widget's element
222218
self.element.on({
223-
touchstart: _touchStartBound,
224-
touchmove: _touchMoveBound,
225-
touchend: _touchEndBound
219+
touchstart: self._touchStartBound,
220+
touchmove: self._touchMoveBound,
221+
touchend: self._touchEndBound
226222
});
227223

228224
// Call the original $.ui.mouse init method
@@ -238,10 +234,15 @@
238234

239235
// Delegate the touch handlers to the widget's element
240236
self.element.off({
241-
touchstart: _touchStartBound,
242-
touchmove: _touchMoveBound,
243-
touchend: _touchEndBound
237+
touchstart: self._touchStartBound,
238+
touchmove: self._touchMoveBound,
239+
touchend: self._touchEndBound
244240
});
241+
242+
// Clean up references
243+
self._touchStartBound = null;
244+
self._touchMoveBound = null;
245+
self._touchEndBound = null;
245246

246247
// Call the original $.ui.mouse destroy method
247248
_mouseDestroy.call(self);

0 commit comments

Comments
 (0)