switching e.preventDefault() on and off so swipe works on android

switching e.preventDefault() on and off so swipe works on android

Here's a snippet of code that triggers events on swipe left and swipe right.

the problem is with androids then need e.preventDefault() to be called to ensure this can happen according to  http://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&groupby=&sort=&id=4549

Here is my code

  1.     var maxTime = 1000,
  2.     // allow movement if < 1000 ms (1 sec)
  3.     maxDistance = 50,
  4.     // swipe movement of 50 pixels triggers the swipe
  5.     target = jQuery('.pageSize'),
  6.     startX = 0,
  7.     startTime = 0,
  8.     touch = "ontouchend" in document,
  9.     startEvent = (touch) ? 'touchstart' : 'mousedown',
  10.     moveEvent = (touch) ? 'touchmove' : 'mousemove',
  11.     endEvent = (touch) ? 'touchend' : 'mouseup';
  12.    
  13.     target.bind(startEvent, function(e) {
  14.         // prevent image drag (Firefox)
  15.         // e.preventDefault();
  16.         startTime = e.timeStamp;
  17.         startX = e.originalEvent.touches ? e.originalEvent.touches[0].pageX : e.pageX;
  18.     }).bind(endEvent, function(e) {
  19.         startTime = 0;
  20.         startX = 0;
  21.     }).bind(moveEvent, function(e) {
  22.         var currentX = e.originalEvent.touches ? e.originalEvent.touches[0].pageX : e.pageX,
  23.             currentDistance = (startX === 0) ? 0 : Math.abs(currentX - startX),
  24.             // allow if movement < 1 sec
  25.             currentTime = e.timeStamp;
  26.         if (startTime !== 0 && currentTime - startTime < maxTime && currentDistance > maxDistance) {
  27.             if (currentX < startX) {
  28.                 // swipe left code here
  29.                 //slideMobile("forward", pageSize);
  30.                
  31.                 console.log("swipeForward");
  32.                 jQuery(window).trigger('swipeForward');
  33.                
  34.             }
  35.             if (currentX > startX) {
  36.                 // swipe right code here
  37.                 //slideMobile("back", pageSize);
  38.                
  39.                 console.log("swipeBackward");
  40.                 jQuery(window).trigger('swipeBackward');
  41.                
  42.                
  43.             }
  44.             startTime = 0;
  45.             startX = 0;
  46.         }
  47.     });

I am struggling to know where to put these e.preventDefault() as surely I need to switch the prevent off afterwards as otherwise after the first swipe it will not do anything?

If I add here

  1.     target.bind(startEvent, function(e) {
  2.     // prevent image drag (Firefox)
  3.      e.preventDefault();
  4.     startTime = e.timeStamp;
  5.     startX = e.originalEvent.touches ? e.originalEvent.touches[0].pageX : e.pageX;
  6.     })

I can now swipe left and right - but the scrolling up and down is disabled due to the prevent default.

Can anyone help?