From c7f935f1c8c5d3b1884eedc4e97095c510226aee Mon Sep 17 00:00:00 2001 From: maxpozdeev Date: Mon, 17 Feb 2025 22:17:25 +0300 Subject: [PATCH] Update jQuery UI Touch Punch to 1.1.5 with my patches --- src/content/js/jquery.ui.touch-punch.js | 116 ++++++++++++------------ src/includes/theme.php | 2 +- 2 files changed, 60 insertions(+), 58 deletions(-) diff --git a/src/content/js/jquery.ui.touch-punch.js b/src/content/js/jquery.ui.touch-punch.js index 4418e47..8cd8d09 100644 --- a/src/content/js/jquery.ui.touch-punch.js +++ b/src/content/js/jquery.ui.touch-punch.js @@ -1,5 +1,5 @@ /*! - * jQuery UI Touch Punch 1.0.8 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 @@ -22,7 +22,7 @@ if ( typeof define === "function" && define.amd ) { // AMD. Register as an anonymous module. - define([ "jquery", "jquery.ui" ], factory ); + define([ "jquery", "jquery-ui" ], factory ); } else { // Browser globals @@ -31,31 +31,30 @@ }(function ($) { // Detect touch support - Windows Surface devices and other touch devices - $.support.mspointer = window.navigator.msPointerEnabled; - $.support.touch = ( 'ontouchstart' in document - || 'ontouchstart' in window - || window.TouchEvent - || (window.DocumentTouch && document instanceof DocumentTouch) - || navigator.maxTouchPoints > 0 - || navigator.msMaxTouchPoints > 0 + $.mspointer = window.navigator.msPointerEnabled; + $.touch = ( 'ontouchstart' in document + || 'ontouchstart' in window + || window.TouchEvent + || (window.DocumentTouch && document instanceof DocumentTouch) + || navigator.maxTouchPoints > 0 + || navigator.msMaxTouchPoints > 0 ); // Ignore browsers without touch or mouse support - if ((!$.support.touch && !$.support.mspointer) || !$.ui.mouse) { - return; + if ((!$.touch && !$.mspointer) || !$.ui.mouse) { + return; } - var mouseProto = $.ui.mouse.prototype, + let mouseProto = $.ui.mouse.prototype, _mouseInit = mouseProto._mouseInit, _mouseDestroy = mouseProto._mouseDestroy, - touchHandled; + touchHandled, lastClickTime = 0; - var delay = 300, + let delay = 300, delayTimer, delayEvent, delayStarted = false, delayFinished = false, - lastClickTimeStamp = 0, lastClickCoord; @@ -82,32 +81,26 @@ return; } + //Ignore input or textarea elements so user can still enter text + if ($(event.target).is("input") || $(event.target).is("textarea")) { + return; + } + // Prevent "Ignored attempt to cancel a touchmove event with cancelable=false" errors if (event.cancelable) { event.preventDefault(); } - var 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 - ); + let touch = event.originalEvent.changedTouches[0], + 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); @@ -125,7 +118,7 @@ function fireMouseDown () { - var self = this; + const self = this; delayFinished = true; @@ -152,7 +145,7 @@ */ mouseProto._touchStart = function (event) { - var self = this; + let self = this; // Interaction time this._startedMove = event.timeStamp; @@ -224,22 +217,23 @@ // If the touch interaction did not move, it should trigger a click // Check for this in two ways - length of time of simulation and distance moved // Allow for Apple Stylus to be used also - var timeMoving = event.timeStamp - this._startedMove; + let timeMoving = event.timeStamp - this._startedMove; if (!this._touchMoved || timeMoving < 500) { - // Simulate the click event - simulateMouseEvent(event, 'click'); - - if (lastClickTimeStamp != 0 && event.timeStamp - lastClickTimeStamp < 500 && + // Simulate the dblclick event if last click was not far away from the previous one + if ( event.timeStamp - lastClickTime < 400 && Math.abs(lastClickCoord.x - this._startPos.x) < 10 && Math.abs(lastClickCoord.y - this._startPos.y) < 10) { - // Simulate the dblclick event simulateMouseEvent(event, 'dblclick'); } - lastClickTimeStamp = event.timeStamp + // Simulate the click event + else + simulateMouseEvent(event, 'click'); + + lastClickTime = event.timeStamp lastClickCoord = this._startPos; } else { - var endPos = getTouchCoords(event); + let endPos = getTouchCoords(event); if ((Math.abs(endPos.x - this._startPos.x) < 10) && (Math.abs(endPos.y - this._startPos.y) < 10)) { // If the touch interaction did not move, it should trigger a click if (!this._touchMoved || event.originalEvent.changedTouches[0].touchType === 'stylus') { @@ -256,6 +250,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 @@ -264,18 +262,22 @@ */ mouseProto._mouseInit = function () { - var self = this; - + let self = this; + // Microsoft Surface Support = remove original touch Action - if ($.support.mspointer) { + if ($.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 @@ -287,13 +289,13 @@ */ mouseProto._mouseDestroy = function () { - var self = this; + let self = this; // 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 diff --git a/src/includes/theme.php b/src/includes/theme.php index b222ab2..1960a3f 100644 --- a/src/includes/theme.php +++ b/src/includes/theme.php @@ -28,7 +28,7 @@ - +