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

Commit 2318203

Browse files
committed
Swipe Event: Rewrite to trigger once threshhold has been reached instead of waiting for vmouse up this emulates native swipe event
1 parent 23cfeed commit 2318203

File tree

2 files changed

+10
-37
lines changed

2 files changed

+10
-37
lines changed

js/events/touch.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ define( [ "jquery", "../jquery.mobile.vmouse", "../jquery.mobile.support.touch"
141141

142142
durationThreshold: 1000, // More time than this, and it isn't a swipe.
143143

144-
horizontalDistanceThreshold: 30, // Swipe horizontal displacement must be more than this.
144+
horizontalDistanceThreshold: 10, // Swipe horizontal displacement must be more than this.
145145

146146
verticalDistanceThreshold: 75, // Swipe vertical displacement must be less than this.
147147

@@ -172,7 +172,10 @@ define( [ "jquery", "../jquery.mobile.vmouse", "../jquery.mobile.support.touch"
172172

173173
triggerCustomEvent( thisObject, "swipe", $.Event( "swipe", { target: origTarget }) );
174174
triggerCustomEvent( thisObject, direction,$.Event( direction, { target: origTarget } ) );
175+
return true;
175176
}
177+
return false;
178+
176179
},
177180

178181
setup: function() {
@@ -182,15 +185,18 @@ define( [ "jquery", "../jquery.mobile.vmouse", "../jquery.mobile.support.touch"
182185
$this.bind( touchStartEvent, function( event ) {
183186
var stop,
184187
start = $.event.special.swipe.start( event ),
185-
origTarget = event.target;
188+
origTarget = event.target,
189+
emitted = false;
186190

187191
function moveHandler( event ) {
188192
if ( !start ) {
189193
return;
190194
}
191195

192196
stop = $.event.special.swipe.stop( event );
193-
197+
if( !emitted ){
198+
emitted = $.event.special.swipe.handleSwipe( start, stop, thisObject, origTarget );
199+
}
194200
// prevent scrolling
195201
if ( Math.abs( start.coords[ 0 ] - stop.coords[ 0 ] ) > $.event.special.swipe.scrollSupressionThreshold ) {
196202
event.preventDefault();
@@ -199,12 +205,7 @@ define( [ "jquery", "../jquery.mobile.vmouse", "../jquery.mobile.support.touch"
199205

200206
$this.bind( touchMoveEvent, moveHandler )
201207
.one( touchStopEvent, function() {
202-
$this.unbind( touchMoveEvent, moveHandler );
203-
204-
if ( start && stop ) {
205-
$.event.special.swipe.handleSwipe( start, stop, thisObject, origTarget );
206-
}
207-
start = stop = undefined;
208+
emitted = false;
208209
});
209210
});
210211
},

tests/unit/event/event_core.js

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -429,34 +429,6 @@
429429
$( "#qunit-fixture" ).trigger("touchmove");
430430
});
431431

432-
asyncTest( "move handler returns when touchstart has been fired since touchstop", function(){
433-
expect( 1 );
434-
435-
// bypass triggered event check
436-
$.Event.prototype.originalEvent = {
437-
touches: false
438-
};
439-
440-
forceTouchSupport();
441-
442-
// ensure the swipe custome event is setup
443-
$( "#qunit-fixture" ).bind('swipe', function(){});
444-
445-
$( "#qunit-fixture" ).trigger("touchstart");
446-
$( "#qunit-fixture" ).trigger("touchend");
447-
448-
$( "#qunit-fixture" ).bind("touchmove", function(){
449-
ok(true, "touchmove bound functions are fired");
450-
start();
451-
});
452-
453-
Math.abs = function(){
454-
ok(false, "shouldn't compare coordinates");
455-
};
456-
457-
$( "#qunit-fixture" ).trigger("touchmove");
458-
});
459-
460432
var nativeSupportTest = function(opts){
461433
$.support.orientation = opts.orientationSupport;
462434
deepEqual($.event.special.orientationchange[opts.method](), opts.returnValue);

0 commit comments

Comments
 (0)