@@ -63,21 +63,37 @@ $.event.special.tap = {
6363 $this = $ ( thisObject ) ;
6464
6565 $this
66- . bind ( touchStartEvent , function ( event ) {
67- if ( event . which && event . which !== 1 ) {
68- return ;
66+ . bind ( "mousedown touchstart" , function ( event ) {
67+ if ( event . which && event . which !== 1 ||
68+ //check if event fired once already by a device that fires both mousedown and touchstart (while supporting both events)
69+ $this . data ( "prevEvent" ) && $this . data ( "prevEvent" ) !== event . type ) {
70+ return false ;
6971 }
7072
73+ //save event type so only this type is let through for a temp duration,
74+ //allowing quick repetitive taps but not duplicative events
75+ $this . data ( "prevEvent" , event . type ) ;
76+ setTimeout ( function ( ) {
77+ $this . removeData ( "prevEvent" ) ;
78+ } , 800 ) ;
79+
7180 var moved = false ,
7281 touching = true ,
7382 origTarget = event . target ,
74- origPos = [ event . pageX , event . pageY ] ,
83+ origEvent = event . originalEvent ,
84+ origPos = event . type == "touchstart" ? [ origEvent . touches [ 0 ] . pageX , origEvent . touches [ 0 ] . pageY ] : [ event . pageX , event . pageY ] ,
7585 originalType ,
7686 timer ;
87+
7788
78- function moveHandler ( ) {
79- if ( ( Math . abs ( origPos [ 0 ] - event . pageX ) > 10 ) ||
80- ( Math . abs ( origPos [ 1 ] - event . pageY ) > 10 ) ) {
89+ function moveHandler ( event ) {
90+ if ( event . type == "scroll" ) {
91+ moved = true ;
92+ return ;
93+ }
94+ var newPageXY = event . type == "touchmove" ? event . originalEvent . touches [ 0 ] : event ;
95+ if ( ( Math . abs ( origPos [ 0 ] - newPageXY . pageX ) > 10 ) ||
96+ ( Math . abs ( origPos [ 1 ] - newPageXY . pageY ) > 10 ) ) {
8197 moved = true ;
8298 }
8399 }
@@ -91,17 +107,21 @@ $.event.special.tap = {
91107 }
92108 } , 750 ) ;
93109
110+ //scroll now cancels tap
111+ $ ( window ) . one ( "scroll" , moveHandler ) ;
112+
94113 $this
95- . one ( touchMoveEvent , moveHandler )
96- . one ( touchStopEvent , function ( event ) {
97- $this . unbind ( touchMoveEvent , moveHandler ) ;
114+ . bind ( "mousemove touchmove" , moveHandler )
115+ . one ( "mouseup touchend" , function ( event ) {
116+ $this . unbind ( "mousemove touchmove" , moveHandler ) ;
117+ $ ( window ) . unbind ( "scroll" , moveHandler ) ;
98118 clearTimeout ( timer ) ;
99119 touching = false ;
100120
101121 /* ONLY trigger a 'tap' event if the start target is
102122 * the same as the stop target.
103123 */
104- if ( ! moved && ( origTarget == event . target ) ) {
124+ if ( ! moved && ( origTarget == event . target ) ) {
105125 originalType = event . type ;
106126 event . type = "tap" ;
107127 $ . event . handle . call ( thisObject , event ) ;
0 commit comments