From 1abf234f1844094060cda1cbfe5904aeaae81d78 Mon Sep 17 00:00:00 2001 From: Domeshow Date: Mon, 8 May 2023 16:24:19 +0200 Subject: [PATCH] [ENH] Drag and drop on mobile without touchpunch --- dist/pivot.js | 68 ++++++++++++++++++++++++++++++++++++++ examples/fully_loaded.html | 1 - examples/onrefresh.html | 1 - 3 files changed, 68 insertions(+), 2 deletions(-) diff --git a/dist/pivot.js b/dist/pivot.js index 489e412a..af36bc32 100644 --- a/dist/pivot.js +++ b/dist/pivot.js @@ -1753,6 +1753,74 @@ return this; }; + /* + Support Touch Event + */ + var supportTouch = function () { + $.support.touch = true; + + if (!$.support.touch) { + return; + } + + var proto = $.ui.mouse.prototype, + _mouseInit = proto._mouseInit; + + $.extend(proto, { + _getElementToBind: function() { + var el = this.element; + return el; + }, + + _mouseInit: function() { + this._getElementToBind().bind("touchstart." + this.widgetName, $.proxy(this, "_touchStart")); + _mouseInit.apply(this, arguments); + }, + + _touchStart: function(event) { + if (event.originalEvent.targetTouches.length != 1) { + return false; + } + + if (!this._mouseCapture(event, false)) { + return true; + } + + this.element + .bind("touchmove." + this.widgetName, $.proxy(this, "_touchMove")) + .bind("touchend." + this.widgetName, $.proxy(this, "_touchEnd")); + + this._modifyEvent(event); + + $(document).trigger($.Event("mouseup")); + this._mouseDown(event); + + return false; + }, + + _touchMove: function(event) { + this._modifyEvent(event); + this._mouseMove(event); + }, + + _touchEnd: function(event) { + this.element + .unbind("touchmove." + this.widgetName) + .unbind("touchend." + this.widgetName); + this._mouseUp(event); + }, + + _modifyEvent: function(event) { + event.which = 1; + var target = event.originalEvent.targetTouches[0]; + event.pageX = target.clientX; + event.pageY = target.clientY; + } + + }); + } + supportTouch(); + /* Barchart post-processing */ diff --git a/examples/fully_loaded.html b/examples/fully_loaded.html index 0e33066b..f146a805 100644 --- a/examples/fully_loaded.html +++ b/examples/fully_loaded.html @@ -8,7 +8,6 @@ - diff --git a/examples/onrefresh.html b/examples/onrefresh.html index 44d21f11..4f2ce459 100644 --- a/examples/onrefresh.html +++ b/examples/onrefresh.html @@ -14,7 +14,6 @@ -