From: Nicolas Coden Date: Wed, 1 Aug 2018 21:57:14 +0000 (+0200) Subject: fix: keep the original event datas in Touch tap/swipe events X-Git-Tag: v6.6.0~3^2~85^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f016a9f2f4896ee36ad933d8d3538bdd38015965;p=thirdparty%2Ffoundation%2Ffoundation-sites.git 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. --- 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();