diff --git a/js/jquery.mobile.event.js b/js/jquery.mobile.event.js index c1bdc90d..3dbd8f3f 100644 --- a/js/jquery.mobile.event.js +++ b/js/jquery.mobile.event.js @@ -63,21 +63,37 @@ $.event.special.tap = { $this = $( thisObject ); $this - .bind( touchStartEvent, function( event ) { - if ( event.which && event.which !== 1 ) { - return; + .bind( "mousedown touchstart", function( event ) { + if ( event.which && event.which !== 1 || + //check if event fired once already by a device that fires both mousedown and touchstart (while supporting both events) + $this.data( "prevEvent") && $this.data( "prevEvent") !== event.type ) { + return false; } + //save event type so only this type is let through for a temp duration, + //allowing quick repetitive taps but not duplicative events + $this.data( "prevEvent", event.type ); + setTimeout(function(){ + $this.removeData( "prevEvent" ); + }, 800); + var moved = false, touching = true, origTarget = event.target, - origPos = [ event.pageX, event.pageY ], + origEvent = event.originalEvent, + origPos = event.type == "touchstart" ? [origEvent.touches[0].pageX, origEvent.touches[0].pageY] : [ event.pageX, event.pageY ], originalType, timer; + - function moveHandler() { - if ((Math.abs(origPos[0] - event.pageX) > 10) || - (Math.abs(origPos[1] - event.pageY) > 10)) { + function moveHandler( event ) { + if( event.type == "scroll" ){ + moved = true; + return; + } + var newPageXY = event.type == "touchmove" ? event.originalEvent.touches[0] : event; + if ((Math.abs(origPos[0] - newPageXY.pageX) > 10) || + (Math.abs(origPos[1] - newPageXY.pageY) > 10)) { moved = true; } } @@ -91,17 +107,21 @@ $.event.special.tap = { } }, 750 ); + //scroll now cancels tap + $(window).one("scroll", moveHandler); + $this - .one( touchMoveEvent, moveHandler) - .one( touchStopEvent, function( event ) { - $this.unbind( touchMoveEvent, moveHandler ); + .bind( "mousemove touchmove", moveHandler ) + .one( "mouseup touchend", function( event ) { + $this.unbind( "mousemove touchmove", moveHandler ); + $(window).unbind("scroll", moveHandler); clearTimeout( timer ); touching = false; /* ONLY trigger a 'tap' event if the start target is * the same as the stop target. */ - if ( !moved && (origTarget == event.target)) { + if ( !moved && ( origTarget == event.target ) ) { originalType = event.type; event.type = "tap"; $.event.handle.call( thisObject, event ); diff --git a/tests/functional/eventlogger.html b/tests/functional/eventlogger.html new file mode 100755 index 00000000..39c7664f --- /dev/null +++ b/tests/functional/eventlogger.html @@ -0,0 +1,37 @@ + + + + + jQuery Mobile: Event Logger + + + + + + + + +
+
+

Event Logger

+
+ +
+

Touch events on this page will log out below, prepending to the top as they arrive.

+ + + +
+
+ +