Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit 3367ec5

Browse files
committed
Swipe: change to use triggerCustomEvent Fixes #5311 - Nested delegate elements cause swipe event duplication
1 parent 72654a1 commit 3367ec5

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

js/events/touch.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,14 @@ define( [ "jquery", "../jquery.mobile.vmouse", "../jquery.mobile.support.touch"
158158
};
159159
},
160160

161-
handleSwipe: function( start, stop ) {
161+
handleSwipe: function( start, stop, thisObject, origTarget ) {
162162
if ( stop.time - start.time < $.event.special.swipe.durationThreshold &&
163163
Math.abs( start.coords[ 0 ] - stop.coords[ 0 ] ) > $.event.special.swipe.horizontalDistanceThreshold &&
164164
Math.abs( start.coords[ 1 ] - stop.coords[ 1 ] ) < $.event.special.swipe.verticalDistanceThreshold ) {
165+
var direction = start.coords[0] > stop.coords[ 0 ] ? "swipeleft" : "swiperight";
165166

166-
start.origin.trigger( "swipe" )
167-
.trigger( start.coords[0] > stop.coords[ 0 ] ? "swipeleft" : "swiperight" );
167+
triggerCustomEvent( thisObject, "swipe", $.Event( "swipe", { target: origTarget }) );
168+
triggerCustomEvent( thisObject, direction,$.Event( direction, { target: origTarget } ) );
168169
}
169170
},
170171

@@ -173,8 +174,9 @@ define( [ "jquery", "../jquery.mobile.vmouse", "../jquery.mobile.support.touch"
173174
$this = $( thisObject );
174175

175176
$this.bind( touchStartEvent, function( event ) {
176-
var start = $.event.special.swipe.start( event ),
177-
stop;
177+
var stop,
178+
start = $.event.special.swipe.start( event ),
179+
origTarget = event.target;
178180

179181
function moveHandler( event ) {
180182
if ( !start ) {
@@ -189,14 +191,14 @@ define( [ "jquery", "../jquery.mobile.vmouse", "../jquery.mobile.support.touch"
189191
}
190192
}
191193

192-
$this.bind( touchMoveEvent, moveHandler );
193-
$document.one( touchStopEvent, function() {
194-
$this.unbind( touchMoveEvent, moveHandler );
194+
$this.bind( touchMoveEvent, moveHandler )
195+
.one( touchStopEvent, function() {
196+
$this.unbind( touchMoveEvent, moveHandler );
195197

196-
if ( start && stop ) {
197-
$.event.special.swipe.handleSwipe( start, stop );
198-
}
199-
start = stop = undefined;
198+
if ( start && stop ) {
199+
$.event.special.swipe.handleSwipe( start, stop, thisObject, origTarget );
200+
}
201+
start = stop = undefined;
200202
});
201203
});
202204
},

0 commit comments

Comments
 (0)