From 3b92410ff31f1b5a47de62037f43bc15479c9eaf Mon Sep 17 00:00:00 2001 From: scottjehl Date: Fri, 14 Jan 2011 15:16:03 -0500 Subject: [PATCH] some additional changes to make scrolling from a select button work ok. --- js/jquery.mobile.forms.select.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/js/jquery.mobile.forms.select.js b/js/jquery.mobile.forms.select.js index a28382e4..9fccfa77 100644 --- a/js/jquery.mobile.forms.select.js +++ b/js/jquery.mobile.forms.select.js @@ -160,17 +160,30 @@ $.widget( "mobile.selectmenu", $.mobile.widget, { //button events button - .bind( $.support.touch ? "touchend" : "click" , function( event ){ + .bind( "touchstart" ,function( event ){ + //set startTouches to cached copy of + $( this ).data( "startTouches", $.extend({}, event.originalEvent.touches[ 0 ]) ); + }) + .bind( $.support.touch ? "touchend" : "mouseup" , function( event ){ + //if it's a scroll, don't open if( $( this ).data( "moved" ) ){ $( this ).removeData( "moved" ); } else{ self.open(); - event.preventDefault(); } + event.preventDefault(); }) - .bind( "touchmove", function(event){ - $( this ).data( "moved", true ); + .bind( "touchmove", function( event ){ + //if touch moved enough, set data moved and don't open menu + var thisTouches = event.originalEvent.touches[ 0 ], + startTouches = $( this ).data( "startTouches" ), + deltaX = Math.abs(thisTouches.pageX - startTouches.pageX), + deltaY = Math.abs(thisTouches.pageY - startTouches.pageY); + + if( deltaX > 10 || deltaY > 10 ){ + $( this ).data( "moved", true ); + } }); //events for list items