Skip to content

Commit

Permalink
jquery.ui.touch-punch.js v1.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Grahn committed Jun 12, 2024
1 parent 4450f10 commit b38a794
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions js/jquery.ui.touch-punch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* jQuery UI Touch Punch 1.0.9 as modified by RWAP Software
* jQuery UI Touch Punch 1.1.5 as modified by RWAP Software
* based on original touchpunch v0.2.3 which has not been updated since 2014
*
* Updates by RWAP Software to take account of various suggested changes on the original code issues
Expand Down Expand Up @@ -45,7 +45,7 @@
let mouseProto = $.ui.mouse.prototype,
_mouseInit = mouseProto._mouseInit,
_mouseDestroy = mouseProto._mouseDestroy,
touchHandled;
touchHandled, lastClickTime = 0;

/**
* Get the x,y position of a touch event
Expand Down Expand Up @@ -81,26 +81,15 @@
}

let touch = event.originalEvent.changedTouches[0],
simulatedEvent = document.createEvent('MouseEvents');

// Initialize the simulated mouse event using the touch event's coordinates
simulatedEvent.initMouseEvent(
simulatedType, // type
true, // bubbles
true, // cancelable
window, // view
1, // detail
touch.screenX, // screenX
touch.screenY, // screenY
touch.clientX, // clientX
touch.clientY, // clientY
false, // ctrlKey
false, // altKey
false, // shiftKey
false, // metaKey
0, // button
null // relatedTarget
);
simulatedEvent = new MouseEvent(simulatedType, {
bubbles: true,
cancelable: true,
view:window,
screenX:touch.screenX,
screenY:touch.screenY,
clientX:touch.clientX,
clientY:touch.clientY
});

// Dispatch the simulated event to the target element
event.target.dispatchEvent(simulatedEvent);
Expand Down Expand Up @@ -182,7 +171,11 @@
let timeMoving = event.timeStamp - this._startedMove;
if (!this._touchMoved || timeMoving < 500) {
// Simulate the click event
simulateMouseEvent(event, 'click');
if( event.timeStamp - lastClickTime < 400 )
simulateMouseEvent(event, 'dblclick');
else
simulateMouseEvent(event, 'click');
lastClickTime = event.timeStamp;
} else {
let endPos = getTouchCoords(event);
if ((Math.abs(endPos.x - this._startPos.x) < 10) && (Math.abs(endPos.y - this._startPos.y) < 10)) {
Expand All @@ -202,6 +195,10 @@
touchHandled = false;
};

let _touchStartBound;
let _touchMoveBound;
let _touchEndBound

/**
* A duck punch of the $.ui.mouse _mouseInit method to support touch events.
* This method extends the widget with bound touch event handlers that
Expand All @@ -215,13 +212,17 @@
// Microsoft Surface Support = remove original touch Action
if ($.support.mspointer) {
self.element[0].style.msTouchAction = 'none';
}
}

_touchStartBound = mouseProto._touchStart.bind(self);
_touchMoveBound = mouseProto._touchMove.bind(self);
_touchEndBound = mouseProto._touchEnd.bind(self);

// Delegate the touch handlers to the widget's element
self.element.on({
touchstart: $.proxy(self, '_touchStart'),
touchmove: $.proxy(self, '_touchMove'),
touchend: $.proxy(self, '_touchEnd')
touchstart: _touchStartBound,
touchmove: _touchMoveBound,
touchend: _touchEndBound
});

// Call the original $.ui.mouse init method
Expand All @@ -237,9 +238,9 @@

// Delegate the touch handlers to the widget's element
self.element.off({
touchstart: $.proxy(self, '_touchStart'),
touchmove: $.proxy(self, '_touchMove'),
touchend: $.proxy(self, '_touchEnd')
touchstart: _touchStartBound,
touchmove: _touchMoveBound,
touchend: _touchEndBound
});

// Call the original $.ui.mouse destroy method
Expand Down
Binary file modified zip/ABLoopPlayer.zip
Binary file not shown.

0 comments on commit b38a794

Please sign in to comment.