Permalink
Browse files

Swipe Event: Rewrite to trigger once threshhold has been reached inst…

…ead of waiting for vmouse up this emulates native swipe event
  • Loading branch information...
arschmitz committed Jun 21, 2013
1 parent 23cfeed commit 231820361f547d8fa0e26f9bfc2ad9e1c9686a68
Showing with 10 additions and 37 deletions.
  1. +10 −9 js/events/touch.js
  2. +0 −28 tests/unit/event/event_core.js
View
@@ -141,7 +141,7 @@ define( [ "jquery", "../jquery.mobile.vmouse", "../jquery.mobile.support.touch"
durationThreshold: 1000, // More time than this, and it isn't a swipe.
- horizontalDistanceThreshold: 30, // Swipe horizontal displacement must be more than this.
+ horizontalDistanceThreshold: 10, // Swipe horizontal displacement must be more than this.
verticalDistanceThreshold: 75, // Swipe vertical displacement must be less than this.
@@ -172,7 +172,10 @@ define( [ "jquery", "../jquery.mobile.vmouse", "../jquery.mobile.support.touch"
triggerCustomEvent( thisObject, "swipe", $.Event( "swipe", { target: origTarget }) );
triggerCustomEvent( thisObject, direction,$.Event( direction, { target: origTarget } ) );
+ return true;
}
+ return false;
+
},
setup: function() {
@@ -182,15 +185,18 @@ define( [ "jquery", "../jquery.mobile.vmouse", "../jquery.mobile.support.touch"
$this.bind( touchStartEvent, function( event ) {
var stop,
start = $.event.special.swipe.start( event ),
- origTarget = event.target;
+ origTarget = event.target,
+ emitted = false;
function moveHandler( event ) {
if ( !start ) {
return;
}
stop = $.event.special.swipe.stop( event );
-
+ if( !emitted ){
+ emitted = $.event.special.swipe.handleSwipe( start, stop, thisObject, origTarget );
+ }
// prevent scrolling
if ( Math.abs( start.coords[ 0 ] - stop.coords[ 0 ] ) > $.event.special.swipe.scrollSupressionThreshold ) {
event.preventDefault();
@@ -199,12 +205,7 @@ define( [ "jquery", "../jquery.mobile.vmouse", "../jquery.mobile.support.touch"
$this.bind( touchMoveEvent, moveHandler )
.one( touchStopEvent, function() {
- $this.unbind( touchMoveEvent, moveHandler );
-
- if ( start && stop ) {
- $.event.special.swipe.handleSwipe( start, stop, thisObject, origTarget );
- }
- start = stop = undefined;
+ emitted = false;
});
});
},
@@ -429,34 +429,6 @@
$( "#qunit-fixture" ).trigger("touchmove");
});
- asyncTest( "move handler returns when touchstart has been fired since touchstop", function(){
- expect( 1 );
-
- // bypass triggered event check
- $.Event.prototype.originalEvent = {
- touches: false
- };
-
- forceTouchSupport();
-
- // ensure the swipe custome event is setup
- $( "#qunit-fixture" ).bind('swipe', function(){});
-
- $( "#qunit-fixture" ).trigger("touchstart");
- $( "#qunit-fixture" ).trigger("touchend");
-
- $( "#qunit-fixture" ).bind("touchmove", function(){
- ok(true, "touchmove bound functions are fired");
- start();
- });
-
- Math.abs = function(){
- ok(false, "shouldn't compare coordinates");
- };
-
- $( "#qunit-fixture" ).trigger("touchmove");
- });
-
var nativeSupportTest = function(opts){
$.support.orientation = opts.orientationSupport;
deepEqual($.event.special.orientationchange[opts.method](), opts.returnValue);

0 comments on commit 2318203

Please sign in to comment.