]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
fix: keep the original event datas in Touch tap/swipe events (v6.5)
authorNicolas Coden <nicolas@ncoden.fr>
Wed, 10 Oct 2018 17:27:41 +0000 (19:27 +0200)
committerNicolas Coden <nicolas@ncoden.fr>
Thu, 11 Oct 2018 19:46:02 +0000 (21:46 +0200)
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.

This is a patch of f016a9f (#11430) for v6.5.

js/foundation.util.touch.js

index 9d0eec9080b99dcd5286e9966934027432aa2fcb..cd46be1f4827cd959c1b8d5132bdbf08b0091059 100644 (file)
@@ -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();