From f016a9f2f4896ee36ad933d8d3538bdd38015965 Mon Sep 17 00:00:00 2001 From: Nicolas Coden Date: Wed, 1 Aug 2018 23:57:14 +0200 Subject: [PATCH] fix: keep the original event datas in Touch tap/swipe events Keep the `touchstart`/`touchmove`/`touchend` datas (like `target`) for the events that are manually triggered: `tap` and `swipe`. This resolve a bug in "Reveal" when a `touchend` event inside the reveal modal is transformed to a `tap` event on the overlay because the original `target` is lost when triggered the event on the overlay. --- js/foundation.util.touch.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/js/foundation.util.touch.js b/js/foundation.util.touch.js index 9d0eec908..cd46be1f4 100644 --- a/js/foundation.util.touch.js +++ b/js/foundation.util.touch.js @@ -11,19 +11,22 @@ var startPosX, startPosY, startTime, elapsedTime, + startEvent, isMoving = false, didMoved = false; -function onTouchEnd() { +function onTouchEnd(e) { this.removeEventListener('touchmove', onTouchMove); this.removeEventListener('touchend', onTouchEnd); // If the touch did not moved, consider it as a "tap" if (!didMoved) { - $(this).trigger('tap'); + var tapEvent = $.Event('tap', startEvent || e); + $(this).trigger(tapEvent); } + startEvent = null; isMoving = false; didMoved = false; } @@ -47,8 +50,10 @@ function onTouchMove(e) { // } if(dir) { e.preventDefault(); - onTouchEnd.call(this); - $(this).trigger('swipe', dir).trigger(`swipe${dir}`); + onTouchEnd.apply(this, arguments); + $(this) + .trigger($.Event('swipe', e), dir) + .trigger($.Event(`swipe${dir}`, e)); } } @@ -59,6 +64,7 @@ function onTouchStart(e) { if (e.touches.length == 1) { startPosX = e.touches[0].pageX; startPosY = e.touches[0].pageY; + startEvent = e; isMoving = true; didMoved = false; startTime = new Date().getTime(); -- 2.47.3