2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								/ *  
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								*  touchSwipe  -  jQuery  Plugin  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  https : //github.com/mattbryson/TouchSwipe-Jquery-Plugin
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  http : //labs.skinkers.com/touchSwipe/
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  http : //plugins.jquery.com/project/touchSwipe
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  Copyright  ( c )  2010  Matt  Bryson  ( www . skinkers . com )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  Dual  licensed  under  the  MIT  or  GPL  Version  2  licenses .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $version :  1.5 . 1  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  Changelog  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $Date :  2010 - 12 - 12  ( Wed ,  12  Dec  2010 )  $  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $version :  1.0 . 0   
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $version :  1.0 . 1  -  removed  multibyte  comments  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $Date :  2011 - 21 - 02  ( Mon ,  21  Feb  2011 )  $  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $version :  1.1 . 0  	-  added  allowPageScroll  property  to  allow  swiping  and  scrolling  of  page  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* 					-  changed  handler  signatures  so  one  handler  can  be  used  for  multiple  events  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $Date :  2011 - 23 - 02  ( Wed ,  23  Feb  2011 )  $  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $version :  1.2 . 0  	-  added  click  handler .  This  is  fired  if  the  user  simply  clicks  and  does  not  swipe .  The  event  object  and  click  target  are  passed  to  handler .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* 					-  If  you  use  the  http : //code.google.com/p/jquery-ui-for-ipad-and-iphone/ plugin, you can also assign jQuery mouse events to children of a touchSwipe object.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $version :  1.2 . 1  	-  removed  console  log !  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $version :  1.2 . 2  	-  Fixed  bug  where  scope  was  not  preserved  in  callback  methods .   
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $Date :  2011 - 28 - 04  ( Thurs ,  28  April  2011 )  $  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $version :  1.2 . 4  	-  Changed  licence  terms  to  be  MIT  or  GPL  inline  with  jQuery .  Added  check  for  support  of  touch  events  to  stop  non  compatible  browsers  erroring .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $Date :  2011 - 27 - 09  ( Tues ,  27  September  2011 )  $  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $version :  1.2 . 5  	-  Added  support  for  testing  swipes  with  mouse  on  desktop  browser  ( thanks  to  https : //github.com/joelhy)
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $Date :  2012 - 14 - 05  ( Mon ,  14  May  2012 )  $  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $version :  1.2 . 6  	-  Added  timeThreshold  between  start  and  end  touch ,  so  user  can  ignore  slow  swipes  ( thanks  to  Mark  Chase ) .  Default  is  null ,  all  swipes  are  detected  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*   
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $Date :  2012 - 05 - 06  ( Tues ,  05  June  2012 )  $  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $version :  1.2 . 7  	-  Changed  time  threshold  to  have  null  default  for  backwards  compatibility .  Added  duration  param  passed  back  in  events ,  and  refactored  how  time  is  handled .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $Date :  2012 - 05 - 06  ( Tues ,  05  June  2012 )  $  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $version :  1.2 . 8  	-  Added  the  possibility  to  return  a  value  like  null  or  false  in  the  trigger  callback .  In  that  way  we  can  control  when  the  touch  start / move  should  take  effect  or  not  ( simply  by  returning  in  some  cases  return  null ;  or  return  false ; )  This  effects  the  ontouchstart / ontouchmove  event .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $Date :  2012 - 06 - 06  ( Wed ,  06  June  2012 )  $  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $version :  1.3 . 0  	-  Refactored  whole  plugin  to  allow  for  methods  to  be  executed ,  as  well  as  exposed  defaults  for  user  override .  Added  'enable' ,  'disable' ,  and  'destroy'  methods  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $Date :  2012 - 05 - 06  ( Fri ,  05  June  2012 )  $  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $version :  1.3 . 1  	-  Bug  fixes   -  bind ( )  with  false  as  last  argument  is  no  longer  supported  in  jQuery  1.6 ,  also ,  if  you  just  click ,  the  duration  is  now  returned  correctly .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $Date :  2012 - 29 - 07  ( Sun ,  29  July  2012 )  $  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $version :  1.3 . 2 	-  Added  fallbackToMouseEvents  option  to  NOT  capture  mouse  events  on  non  touch  devices .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  			-  Added  "all"  fingers  value  to  the  fingers  property ,  so  any  combinatin  of  fingers  triggers  the  swipe ,  allowing  event  handlers  to  check  the  finger  count  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $Date :  2012 - 09 - 08  ( Thurs ,  9  Aug  2012 )  $  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $version :  1.3 . 3 	-  Code  tidy  prep  for  minified  version  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $Date :  2012 - 04 - 10  ( wed ,  4  Oct  2012 )  $  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $version :  1.4 . 0 	-  Added  pinch  support ,  pinchIn  and  pinchOut  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $Date :  2012 - 11 - 10  ( Thurs ,  11  Oct  2012 )  $  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $version :  1.5 . 0 	-  Added  excludedElements ,  a  jquery  selector  that  specifies  child  elements  that  do  NOT  trigger  swipes .  By  default ,  this  is  one  select  that  removes  all  form ,  input  select ,  button  and  anchor  elements .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $Date :  2012 - 22 - 10  ( Mon ,  22  Oct  2012 )  $  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  $version :  1.5 . 1 	-  Fixed  bug  with  jQuery  1.8  and  trailing  comma  in  excludedElements  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  A  jQuery  plugin  to  capture  left ,  right ,  up  and  down  swipes  on  touch  devices .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  You  can  capture  2  finger  or  1  finger  swipes ,  set  the  threshold  and  define  either  a  catch  all  handler ,  or  individual  direction  handlers .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  Options :  The  defaults  can  be  overridden  by  setting  them  in  $ . fn . swipe . defaults  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  		swipe  			Function  	A  catch  all  handler  that  is  triggered  for  all  swipe  directions .  Handler  is  passed  3  arguments ,  the  original  event  object ,  the  direction  of  the  swipe  :  "left" ,  "right" ,  "up" ,  "down"  ,  the  distance  of  the  swipe ,  the  duration  of  the  swipe  and  the  finger  count .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  		swipeLeft 		Function  	A  handler  that  is  triggered  for  "left"  swipes .  Handler  is  passed  3  arguments ,  the  original  event  object ,  the  direction  of  the  swipe  :  "left" ,  "right" ,  "up" ,  "down"   ,  the  distance  of  the  swipe ,  the  duration  of  the  swipe  and  the  finger  count .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  		swipeRight 		Function  	A  handler  that  is  triggered  for  "right"  swipes .  Handler  is  passed  3  arguments ,  the  original  event  object ,  the  direction  of  the  swipe  :  "left" ,  "right" ,  "up" ,  "down"   ,  the  distance  of  the  swipe ,  the  duration  of  the  swipe  and  the  finger  count .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  		swipeUp 			Function  	A  handler  that  is  triggered  for  "up"  swipes .  Handler  is  passed  3  arguments ,  the  original  event  object ,  the  direction  of  the  swipe  :  "left" ,  "right" ,  "up" ,  "down"  ,  the  distance  of  the  swipe ,  the  duration  of  the  swipe  and  the  finger  count .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  		swipeDown 		Function  	A  handler  that  is  triggered  for  "down"  swipes .  Handler  is  passed  3  arguments ,  the  original  event  object ,  the  direction  of  the  swipe  :  "left" ,  "right" ,  "up" ,  "down"   ,  the  distance  of  the  swipe ,  the  duration  of  the  swipe  and  the  finger  count .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* 		swipeStatus  	Function  	A  handler  triggered  for  every  phase  of  the  swipe .  Handler  is  passed  4  arguments :  event  :  The  original  event  object ,  phase : The  current  swipe  phase ,  either  "start" ,  "move" ,  "end"  or  "cancel" .  direction  :  The  swipe  direction ,  either  "up?, " down ? ,  "left "  or  " right ? . distance  :  The  distance  of  the  swipe . Duration  :  The  duration  of  the  swipe  :   The  finger  count  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* 		 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  		pinchIn 			Function  	A  handler  triggered  when  the  user  pinch  zooms  inward .  Handler  is  passed   
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  		pinchOut 		Function  	A  handler  triggered  when  the  user  pinch  zooms  outward .  Handler  is  passed  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  		pinchStatus 		Function  	A  handler  triggered  for  every  phase  of  a  pinch .  Handler  is  passed  4  arguments :  event  :  The  original  event  object ,  phase : The  current  swipe  face ,  either  "start" ,  "move" ,  "end"  or  "cancel" .  direction  :  The  swipe  direction ,  either  "in"  or  "out" .  distance  :  The  distance  of  the  pinch ,  zoom :  the  pinch  zoom  level  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  		 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  		click 			Function 	A  handler  triggered  when  a  user  just  clicks  on  the  item ,  rather  than  swipes  it .  If  they  do  not  move ,  click  is  triggered ,  if  they  do  move ,  it  is  not .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  		fingers  		int  		Default  1.  	The  number  of  fingers  to  trigger  the  swipe ,  1  or  2.  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  		threshold  		int   		Default  75. 	The  number  of  pixels  that  the  user  must  move  their  finger  by  before  it  is  considered  a  swipe .  
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								*  		maxTimeThreshold  	int   		Default  null .  Time ,  in  milliseconds ,  between  touchStart  and  touchEnd  must  NOT  exceed  in  order  to  be  considered  a  swipe .  
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								* 		triggerOnTouchEnd  Boolean  Default  true  If  true ,  the  swipe  events  are  triggered  when  the  touch  end  event  is  received  ( user  releases  finger ) .   If  false ,  it  will  be  triggered  on  reaching  the  threshold ,  and  then  cancel  the  touch  event  automatically .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* 		allowPageScroll  String  Default  "auto" .  How  the  browser  handles  page  scrolls  when  the  user  is  swiping  on  a  touchSwipe  object .   
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* 										"auto"  :  all  undefined  swipes  will  cause  the  page  to  scroll  in  that  direction .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* 										"none"  :  the  page  will  not  scroll  when  user  swipes .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* 										"horizontal"  :  will  force  page  to  scroll  on  horizontal  swipes .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* 										"vertical"  :  will  force  page  to  scroll  on  vertical  swipes .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* 		fallbackToMouseEvents  	Boolean 		Default  true 	if  true  mouse  events  are  used  when  run  on  a  non  touch  device ,  false  will  stop  swipes  being  triggered  by  mouse  events  on  non  tocuh  devices  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* 		excludedElements 	String  	jquery  selector  that  specifies  child  elements  that  do  NOT  trigger  swipes .  By  default ,  this  is  one  select  that  removes  all  input ,  select ,  textarea ,  button  and  anchor  elements  as  well  as  any  . noSwipe  classes .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  Methods :  To  be  executed  as  strings ,  $el . swipe ( 'disable' ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* 		disable 		Will  disable  all  touch  events  until  enabled  again  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* 		enable 		Will  re - enable  the  touch  events  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* 		destroy 		Will  kill  the  plugin ,  and  it  must  be  re - instantiated  if  it  needs  to  be  used  again  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  This  jQuery  plugin  will  only  run  on  devices  running  Mobile  Webkit  based  browsers  ( iOS  2.0 + ,  android  2.2 + )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* /  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								( function  ( $ )  {  
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									//Constants
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  LEFT  =  "left" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										RIGHT  =  "right" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										UP  =  "up" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										DOWN  =  "down" , 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										IN  =  "in" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										OUT  =  "out" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										NONE  =  "none" , 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										AUTO  =  "auto" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										HORIZONTAL  =  "horizontal" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										VERTICAL  =  "vertical" , 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ALL _FINGERS  =  "all" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										PHASE _START  =  "start" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										PHASE _MOVE  =  "move" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										PHASE _END  =  "end" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										PHASE _CANCEL  =  "cancel" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										SUPPORTS _TOUCH  =  'ontouchstart'  in  window , 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										PLUGIN _NS  =  'TouchSwipe' ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Default thresholds & swipe functions
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  defaults  =  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										fingers :  1 ,  		// int - The number of fingers to trigger the swipe, 1 or 2. Default is 1.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										threshold :  75 ,  		// int - The number of pixels that the user must move their finger by before it is considered a swipe. Default is 75.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										maxTimeThreshold :  null ,  // int - Time, in milliseconds, between touchStart and touchEnd must NOT exceed in order to be considered a swipe.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										swipe :  null ,  		// Function - A catch all handler that is triggered for all swipe directions. Accepts 2 arguments, the original event object, the direction of the swipe : "left", "right", "up", "down", and the finger count.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										swipeLeft :  null ,  	// Function - A handler that is triggered for "left" swipes. Accepts 3 arguments, the original event object, the direction of the swipe : "left", "right", "up", "down", the distance of the swipe, and the finger count.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										swipeRight :  null ,  	// Function - A handler that is triggered for "right" swipes. Accepts 3 arguments, the original event object, the direction of the swipe : "left", "right", "up", "down", the distance of the swipe, and the finger count.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										swipeUp :  null ,  		// Function - A handler that is triggered for "up" swipes. Accepts 3 arguments, the original event object, the direction of the swipe : "left", "right", "up", "down", the distance of the swipe, and the finger count.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										swipeDown :  null ,  	// Function - A handler that is triggered for "down" swipes. Accepts 3 arguments, the original event object, the direction of the swipe : "left", "right", "up", "down", the distance of the swipe, and the finger count.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										swipeStatus :  null ,  	// Function - A handler triggered for every phase of the swipe. Handler is passed 4 arguments: event : The original event object, phase:The current swipe phase, either "start, "move, "end or "cancel. direction : The swipe direction, either "up", "down", "left" or "right". distance : The distance of the swipe, fingerCount: The finger count.
 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										pinchIn : null , 		// Function - A handler triggered for pinch in events. Handler is passed 4 arguments: event : The original event object, direction : The swipe direction, either "in" or "out". distance : The distance of the pinch, zoom: the pinch zoom level
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										pinchOut : null , 		// Function - A handler triggered for pinch in events. Handler is passed 4 arguments: event : The original event object, direction : The swipe direction, either "in" or "out". distance : The distance of the pinch, zoom: the pinch zoom level
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										pinchStatus : null , 	// Function - A handler triggered for every phase of a pinch. Handler is passed 4 arguments: event : The original event object, phase:The current swipe face, either "start", "move", "end" or "cancel". direction : The swipe direction, either "in" or "out". distance : The distance of the pinch, zoom: the pinch zoom level
 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										click :  null ,  		// Function	- A handler triggered when a user just clicks on the item, rather than swipes it. If they do not move, click is triggered, if they do move, it is not.
 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										triggerOnTouchEnd :  true ,  // Boolean, if true, the swipe events are triggered when the touch end event is received (user releases finger).  If false, it will be triggered on reaching the threshold, and then cancel the touch event automatically.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allowPageScroll :  "auto" ,  	/ *   H o w   t h e   b r o w s e r   h a n d l e s   p a g e   s c r o l l s   w h e n   t h e   u s e r   i s   s w i p i n g   o n   a   t o u c h S w i p e   o b j e c t .   
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
																		"auto"  :  all  undefined  swipes  will  cause  the  page  to  scroll  in  that  direction . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																		"none"  :  the  page  will  not  scroll  when  user  swipes . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																		"horizontal"  :  will  force  page  to  scroll  on  horizontal  swipes . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																		"vertical"  :  will  force  page  to  scroll  on  vertical  swipes . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	* / 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										fallbackToMouseEvents :  true , 	//Boolean, if true mouse events are used when run on a non touch device, false will stop swipes being triggered by mouse events on non tocuh devices
 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										excludedElements : "button, input, select, textarea, a, .noSwipe"  //a jquery selector that specifies child elements that do NOT trigger swipes. By default, this is one select that removes all form, input select, button and anchor elements.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									/ * * 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									*  Main  plugin  entry  point  for  jQuery 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									*  This  allows  us  to  pass  options  object  for  instantiation , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									*  as  well  as  execute  methods  by  name  as  per  jQuery  plugin  architecture 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									* / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									$ . fn . swipe  =  function  ( method )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										var  $this  =  $ ( this ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											plugin  =  $this . data ( PLUGIN _NS ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										//Check if we are already instantiated and trying to execute a method	
 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( plugin  &&  typeof  method  ===  'string' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( plugin [ method ] )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												return  plugin [ method ] . apply ( this ,  Array . prototype . slice . call ( arguments ,  1 ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												$ . error ( 'Method '  +  method  +  ' does not exist on jQuery.swipe' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										//Else not instantiated and trying to pass init object (or nothing)
 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										else  if  ( ! plugin  &&  ( typeof  method  ===  'object'  ||  ! method ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											return  init . apply ( this ,  arguments ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  $this ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									//Expose our defaults so a user could override the plugin defaults
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									$ . fn . swipe . defaults  =  defaults ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									//Expose our phase constants - READ ONLY
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									$ . fn . swipe . phases  =  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										PHASE _START :  PHASE _START , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										PHASE _MOVE :  PHASE _MOVE , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										PHASE _END :  PHASE _END , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										PHASE _CANCEL :  PHASE _CANCEL 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									//Expose our direction constants - READ ONLY
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									$ . fn . swipe . directions  =  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										LEFT :  LEFT , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										RIGHT :  RIGHT , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										UP :  UP , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										DOWN :  DOWN , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										IN  :  IN , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										OUT :  OUT 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									//Expose our page scroll directions - READ ONLY
 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									$ . fn . swipe . pageScroll  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										NONE :  NONE , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										HORIZONTAL :  HORIZONTAL , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										VERTICAL :  VERTICAL , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										AUTO :  AUTO 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									//EXPOSE our fingers values - READ ONLY
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									$ . fn . swipe . fingers  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ONE :  1 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										TWO :  2 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										THREE :  3 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ALL :  ALL _FINGERS 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									/ * * 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									*  Initialise  the  plugin  for  each  DOM  element  matched 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									*  This  creates  a  new  instance  of  the  main  TouchSwipe  class  for  each  DOM  element ,  and  then  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									*  saves  a  reference  to  that  instance  in  the  elements  data  property . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									* / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									function  init ( options )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										//Prep and extend the options
 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( options  &&  ( options . allowPageScroll  ===  undefined  &&  ( options . swipe  !==  undefined  ||  options . swipeStatus  !==  undefined ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											options . allowPageScroll  =  NONE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( ! options )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											options  =  { } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										//pass empty object so we dont modify the defaults
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										options  =  $ . extend ( { } ,  $ . fn . swipe . defaults ,  options ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										//For each element instantiate the plugin
 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  this . each ( function  ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											var  $this  =  $ ( this ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											//Check we havent already initialised the plugin
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											var  plugin  =  $this . data ( PLUGIN _NS ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( ! plugin )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												plugin  =  new  touchSwipe ( this ,  options ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$this . data ( PLUGIN _NS ,  plugin ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									/ * * 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									*  Main  TouchSwipe  Plugin  Class 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									* / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									function  touchSwipe ( element ,  options )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										var  useTouchEvents  =  ( SUPPORTS _TOUCH  ||  ! options . fallbackToMouseEvents ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											START _EV  =  useTouchEvents  ?  'touchstart'  :  'mousedown' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											MOVE _EV  =  useTouchEvents  ?  'touchmove'  :  'mousemove' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											END _EV  =  useTouchEvents  ?  'touchend'  :  'mouseup' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											CANCEL _EV  =  'touchcancel' ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										var  distance  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										var  direction  =  null ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										var  duration  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										var  startTouchesDistance = 0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										var  endTouchesDistance = 0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										var  pinchZoom  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										var  pinchDirection = 0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										//jQuery wrapped element for this instance
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										var  $element  =  $ ( element ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										var  phase  =  "start" ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										var  fingerCount  =  0 ;  		// the current number of fingers being used.	
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										//track mouse points / delta
 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										var  fingerData = null ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										//track times
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										var  startTime  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										var  endTime  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										// Add gestures to all swipable areas if supported
 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										try  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											$element . bind ( START _EV ,  touchStart ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$element . bind ( CANCEL _EV ,  touchCancel ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										catch  ( e )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$ . error ( 'events not supported '  +  START _EV  +  ','  +  CANCEL _EV  +  ' on jQuery.swipe' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										//Public methods
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										*  re - enables  the  swipe  plugin  with  the  previous  configuration 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										* / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										this . enable  =  function  ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											$element . bind ( START _EV ,  touchStart ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$element . bind ( CANCEL _EV ,  touchCancel ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											return  $element ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										*  disables  the  swipe  plugin 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										* / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										this . disable  =  function  ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											removeListeners ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  $element ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										*  Destroy  the  swipe  plugin  completely .  To  use  any  swipe  methods ,  you  must  re  initialise  the  plugin . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										* / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										this . destroy  =  function  ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											removeListeners ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$element . data ( PLUGIN _NS ,  null ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  $element ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										//Private methods
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										*  Event  handler  for  a  touch  start  event .  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										*  Stops  the  default  click  event  from  triggering  and  stores  where  we  touched 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										* / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										function  touchStart ( event )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											//If we already in a touch event (a finger already in use) then ignore subsequent ones..
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if (  getTouchInProgress ( )  ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											//Check if this element matches any in the excluded elements selectors,  or its parent is excluded, if so, DONT swipe
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if (  $ ( event . target ) . closest (  options . excludedElements ,  $element  ) . length > 0  )  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											//As we use Jquery bind for events, we need to target the original event object
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											event  =  event . originalEvent ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											var  ret , 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												evt  =  SUPPORTS _TOUCH  ?  event . touches [ 0 ]  :  event ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											phase  =  PHASE _START ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											//If we support touches, get the finger count
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( SUPPORTS _TOUCH )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												// get the total number of fingers touching the screen
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												fingerCount  =  event . touches . length ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											//Else this is the desktop, so stop the browser from dragging the image
 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											else  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												event . preventDefault ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											//clear vars..
 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											distance  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											direction  =  null ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											pinchDirection = null ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											duration  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											startTouchesDistance = 0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											endTouchesDistance = 0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											pinchZoom  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											fingerData = createFingerData ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											// check the number of fingers is what we are looking for, or we are capturing pinches
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( ! SUPPORTS _TOUCH  ||  ( fingerCount  ===  options . fingers  ||  options . fingers  ===  ALL _FINGERS )  ||  hasPinches ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												// get the coordinates of the touch
 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												fingerData [ 0 ] . start . x  =  fingerData [ 0 ] . end . x  =  evt . pageX ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												fingerData [ 0 ] . start . y  =  fingerData [ 0 ] . end . y  =  evt . pageY ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												startTime  =  getTimeStamp ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												if ( fingerCount == 2 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													//Keep track of the initial pinch distance, so we can calculate the diff later
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													//Store second finger data as start
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													fingerData [ 1 ] . start . x  =  fingerData [ 1 ] . end . x  =  event . touches [ 1 ] . pageX ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													fingerData [ 1 ] . start . y  =  fingerData [ 1 ] . end . y  =  event . touches [ 1 ] . pageY ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													startTouchesDistance  =  endTouchesDistance  =  calculateTouchesDistance ( fingerData [ 0 ] . start ,  fingerData [ 1 ] . start ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if  ( options . swipeStatus  ||  options . pinchStatus )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
													ret  =  triggerHandler ( event ,  phase ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											else  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												//A touch with more or less than the fingers we are looking for, so cancel
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												touchCancel ( event ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												ret  =  false ;  // actualy cancel so we dont register event...
 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											//If we have a return value from the users handler, then return and cancel
 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( ret  ===  false )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												phase  =  PHASE _CANCEL ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												triggerHandler ( event ,  phase ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												return  ret ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												setTouchInProgress ( true ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												$element . bind ( MOVE _EV ,  touchMove ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$element . bind ( END _EV ,  touchEnd ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										*  Event  handler  for  a  touch  move  event .  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										*  If  we  change  fingers  during  move ,  then  cancel  the  event 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										* / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										function  touchMove ( event )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											//As we use Jquery bind for events, we need to target the original event object
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											event  =  event . originalEvent ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( phase  ===  PHASE _END  ||  phase  ===  PHASE _CANCEL ) 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												return ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											var  ret , 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												evt  =  SUPPORTS _TOUCH  ?  event . touches [ 0 ]  :  event ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											//Save the first finger data
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											fingerData [ 0 ] . end . x  =  SUPPORTS _TOUCH  ?  event . touches [ 0 ] . pageX  :  evt . pageX ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											fingerData [ 0 ] . end . y  =  SUPPORTS _TOUCH  ?  event . touches [ 0 ] . pageY  :  evt . pageY ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											endTime  =  getTimeStamp ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											direction  =  calculateDirection ( fingerData [ 0 ] . start ,  fingerData [ 0 ] . end ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( SUPPORTS _TOUCH )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												fingerCount  =  event . touches . length ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											phase  =  PHASE _MOVE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											//If we have 2 fingers get Touches distance as well
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if ( fingerCount == 2 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												//Keep track of the initial pinch distance, so we can calculate the diff later
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												//We do this here as well as the start event, incase they start with 1 finger, and the press 2 fingers
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if ( startTouchesDistance == 0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													//Store second finger data as start
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													fingerData [ 1 ] . start . x  =  event . touches [ 1 ] . pageX ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													fingerData [ 1 ] . start . y  =  event . touches [ 1 ] . pageY ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													startTouchesDistance  =  endTouchesDistance  =  calculateTouchesDistance ( fingerData [ 0 ] . start ,  fingerData [ 1 ] . start ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													//Store second finger data as end
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													fingerData [ 1 ] . end . x  =  event . touches [ 1 ] . pageX ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													fingerData [ 1 ] . end . y  =  event . touches [ 1 ] . pageY ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													endTouchesDistance  =  calculateTouchesDistance ( fingerData [ 0 ] . end ,  fingerData [ 1 ] . end ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													pinchDirection  =  calculatePinchDirection ( fingerData [ 0 ] . end ,  fingerData [ 1 ] . end ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												pinchZoom  =  calculatePinchZoom ( startTouchesDistance ,  endTouchesDistance ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( ( fingerCount  ===  options . fingers  ||  options . fingers  ===  ALL _FINGERS )  ||  ! SUPPORTS _TOUCH )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												//Check if we need to prevent default evnet (page scroll / pinch zoom) or not
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												validateDefaultEvent ( event ,  direction ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												//Distance and duration are all off the main finger
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												distance  =  calculateDistance ( fingerData [ 0 ] . start ,  fingerData [ 0 ] . end ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												duration  =  calculateDuration ( fingerData [ 0 ] . start ,  fingerData [ 0 ] . end ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if  ( options . swipeStatus  ||  options . pinchStatus )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													ret  =  triggerHandler ( event ,  phase ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												//If we trigger whilst dragging, not on touch end, then calculate now...
 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												if  ( ! options . triggerOnTouchEnd )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
													var  cancel  =  ! validateSwipeTime ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
													// if the user swiped more than the minimum length, perform the appropriate action
 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													if  ( validateSwipeDistance ( )  ===  true )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
														phase  =  PHASE _END ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														ret  =  triggerHandler ( event ,  phase ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													}  else  if  ( cancel )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
														phase  =  PHASE _CANCEL ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														triggerHandler ( event ,  phase ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											else  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												phase  =  PHASE _CANCEL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												triggerHandler ( event ,  phase ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( ret  ===  false )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												phase  =  PHASE _CANCEL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												triggerHandler ( event ,  phase ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										*  Event  handler  for  a  touch  end  event .  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										*  Calculate  the  direction  and  trigger  events 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										* / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										function  touchEnd ( event )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											//As we use Jquery bind for events, we need to target the original event object
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											event  =  event . originalEvent ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											//If we are still in a touch another finger is down, then dont cancel
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if ( event . touches  &&  event . touches . length > 0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											event . preventDefault ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											endTime  =  getTimeStamp ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											//If we have any touches distance data (they pinched at some point) get Touches distance as well
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if ( startTouchesDistance != 0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												endTouchesDistance  =  calculateTouchesDistance ( fingerData [ 0 ] . end ,  fingerData [ 1 ] . end ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												pinchZoom  =  calculatePinchZoom ( startTouchesDistance ,  endTouchesDistance ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												pinchDirection  =  calculatePinchDirection ( fingerData [ 0 ] . end ,  fingerData [ 1 ] . end ) ; 	
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											distance  =  calculateDistance ( fingerData [ 0 ] . start ,  fingerData [ 0 ] . end ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											direction  =  calculateDirection ( fingerData [ 0 ] . start ,  fingerData [ 0 ] . end ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											duration  =  calculateDuration ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											//If we trigger handlers at end of swipe OR, we trigger during, but they didnt trigger and we are still in the move phase
 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( options . triggerOnTouchEnd  ||  ( options . triggerOnTouchEnd  ===  false  &&  phase  ===  PHASE _MOVE ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												phase  =  PHASE _END ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												// Validate the types of swipe we are looking for
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												//Either we are listening for a pinch, and got one, or we are NOT listening so dont care.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												var  hasValidPinchResult  =  didPinch ( )  ||  ! hasPinches ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												//The number of fingers we want were matched, or on desktop we ignore
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												var  hasCorrectFingerCount  =  ( ( fingerCount  ===  options . fingers  ||  options . fingers  ===  ALL _FINGERS )  ||  ! SUPPORTS _TOUCH ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												//We have an end value for the finger
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												var  hasEndPoint  =  fingerData [ 0 ] . end . x  !==  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												//Check if the above conditions are met to make this swipe count...
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												var  isSwipe  =  ( hasCorrectFingerCount  &&  hasEndPoint  &&  hasValidPinchResult ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												//If we are in a swipe, validate the time and distance...
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if  ( isSwipe )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													var  hasValidTime  =  validateSwipeTime ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													//Check the distance meets threshold settings
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													var  hasValidDistance  =  validateSwipeDistance ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
													
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// if the user swiped more than the minimum length, perform the appropriate action
 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													// hasValidDistance is null when no distance is set 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													if  ( ( hasValidDistance  ===  true  ||  hasValidDistance  ===  null )  &&  hasValidTime )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
														triggerHandler ( event ,  phase ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													else  if  ( ! hasValidTime  ||  hasValidDistance  ===  false )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
														phase  =  PHASE _CANCEL ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														triggerHandler ( event ,  phase ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												else  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
													phase  =  PHASE _CANCEL ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													triggerHandler ( event ,  phase ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											else  if  ( phase  ===  PHASE _MOVE )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												phase  =  PHASE _CANCEL ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												triggerHandler ( event ,  phase ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											$element . unbind ( MOVE _EV ,  touchMove ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$element . unbind ( END _EV ,  touchEnd ,  false ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											setTouchInProgress ( false ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										*  Event  handler  for  a  touch  cancel  event .  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										*  Clears  current  vars 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										* / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										function  touchCancel ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											// reset the variables back to default values
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											fingerCount  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											endTime  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											startTime  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											startTouchesDistance = 0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											endTouchesDistance = 0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											pinchZoom = 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											setTouchInProgress ( false ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										*  Trigger  the  relevant  event  handler 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										*  The  handlers  are  passed  the  original  event ,  the  element  that  was  swiped ,  and  in  the  case  of  the  catch  all  handler ,  the  direction  that  was  swiped ,  "left" ,  "right" ,  "up" ,  or  "down" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										* / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										function  triggerHandler ( event ,  phase )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											var  ret  =  undefined ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											//update status
 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( options . swipeStatus )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												ret  =  options . swipeStatus . call ( $element ,  event ,  phase ,  direction  ||  null ,  distance  ||  0 ,  duration  ||  0 ,  fingerCount ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( options . pinchStatus  &&  didPinch ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												ret  =  options . pinchStatus . call ( $element ,  event ,  phase ,  pinchDirection  ||  null ,  endTouchesDistance  ||  0 ,  duration  ||  0 ,  fingerCount ,  pinchZoom ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( phase  ===  PHASE _CANCEL )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if  ( options . click  &&  ( fingerCount  ===  1  ||  ! SUPPORTS _TOUCH )  &&  ( isNaN ( distance )  ||  distance  ===  0 ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													ret  =  options . click . call ( $element ,  event ,  event . target ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( phase  ==  PHASE _END )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												//trigger catch all event handler
 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												if  ( options . swipe )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													ret  =  options . swipe . call ( $element ,  event ,  direction ,  distance ,  duration ,  fingerCount ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												//trigger direction specific event handlers	
 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												switch  ( direction )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													case  LEFT : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														if  ( options . swipeLeft )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															ret  =  options . swipeLeft . call ( $element ,  event ,  direction ,  distance ,  duration ,  fingerCount ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
														break ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													case  RIGHT : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														if  ( options . swipeRight )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															ret  =  options . swipeRight . call ( $element ,  event ,  direction ,  distance ,  duration ,  fingerCount ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
														break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													case  UP : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														if  ( options . swipeUp )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															ret  =  options . swipeUp . call ( $element ,  event ,  direction ,  distance ,  duration ,  fingerCount ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
														break ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													case  DOWN : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														if  ( options . swipeDown )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															ret  =  options . swipeDown . call ( $element ,  event ,  direction ,  distance ,  duration ,  fingerCount ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												switch  ( pinchDirection )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													case  IN : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														if  ( options . pinchIn )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															ret  =  options . pinchIn . call ( $element ,  event ,  pinchDirection  ||  null ,  endTouchesDistance  ||  0 ,  duration  ||  0 ,  fingerCount ,  pinchZoom ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
														break ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													case  OUT : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														if  ( options . pinchOut )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															ret  =  options . pinchOut . call ( $element ,  event ,  pinchDirection  ||  null ,  endTouchesDistance  ||  0 ,  duration  ||  0 ,  fingerCount ,  pinchZoom ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														break ; 	
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( phase  ===  PHASE _CANCEL  ||  phase  ===  PHASE _END )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												//Manually trigger the cancel handler to clean up data
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												touchCancel ( event ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  ret ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										*  Checks  the  user  has  swipe  far  enough 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										* / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										function  validateSwipeDistance ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( options . threshold  !==  null )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												return  distance  >=  options . threshold ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  null ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										*  Checks  that  the  time  taken  to  swipe  meets  the  minimum  /  maximum  requirements 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										* / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										function  validateSwipeTime ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											var  result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											//If no time set, then return true
 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( options . maxTimeThreshold )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if  ( duration  >=  options . maxTimeThreshold )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
													result  =  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
													result  =  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											else  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												result  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  result ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										*  Checks  direction  of  the  swipe  and  the  value  allowPageScroll  to  see  if  we  should  allow  or  prevent  the  default  behaviour  from  occurring . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										*  This  will  essentially  allow  page  scrolling  or  not  when  the  user  is  swiping  on  a  touchSwipe  object . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										* / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										function  validateDefaultEvent ( event ,  direction )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( options . allowPageScroll  ===  NONE  ||  hasPinches ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												event . preventDefault ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												var  auto  =  options . allowPageScroll  ===  AUTO ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												switch  ( direction )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													case  LEFT : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														if  ( ( options . swipeLeft  &&  auto )  ||  ( ! auto  &&  options . allowPageScroll  !=  HORIZONTAL ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
															event . preventDefault ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														} 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
														break ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													case  RIGHT : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														if  ( ( options . swipeRight  &&  auto )  ||  ( ! auto  &&  options . allowPageScroll  !=  HORIZONTAL ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
															event . preventDefault ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														} 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
														break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													case  UP : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														if  ( ( options . swipeUp  &&  auto )  ||  ( ! auto  &&  options . allowPageScroll  !=  VERTICAL ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
															event . preventDefault ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														} 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
														break ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													case  DOWN : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														if  ( ( options . swipeDown  &&  auto )  ||  ( ! auto  &&  options . allowPageScroll  !=  VERTICAL ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
															event . preventDefault ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														} 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
														break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										*  Calcualte  the  duration  of  the  swipe 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										* / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										function  calculateDuration ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  endTime  -  startTime ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										*  Calculate  the  distance  between  2  touches  ( pinch ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										* / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										function  calculateTouchesDistance ( startPoint ,  endPoint )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											var  diffX  =  Math . abs ( startPoint . x  -  endPoint . x ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											var  diffY  =  Math . abs ( startPoint . y  -  endPoint . y ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  Math . round ( Math . sqrt ( diffX * diffX + diffY * diffY ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										*  Calculate  the  zoom  factor  between  the  start  and  end  distances 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										* / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										function  calculatePinchZoom ( startDistance ,  endDistance )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											var  percent  =  ( endDistance / startDistance )  *  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  percent . toFixed ( 2 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										*  Returns  the  pinch  direction ,  either  IN  or  OUT  for  the  given  points 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										* / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										function  calculatePinchDirection ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if ( pinchZoom < 1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  OUT ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  IN ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										*  Calculate  the  length  /  distance  of  the  swipe 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										*  @ param  finger  A  finger  object  containing  start  and  end  points 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										* / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										function  calculateDistance ( startPoint ,  endPoint )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  Math . round ( Math . sqrt ( Math . pow ( endPoint . x  -  startPoint . x ,  2 )  +  Math . pow ( endPoint . y  -  startPoint . y ,  2 ) ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										*  Calcualte  the  angle  of  the  swipe 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										*  @ param  finger  A  finger  object  containing  start  and  end  points 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										* / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										function  caluculateAngle ( startPoint ,  endPoint )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											var  x  =  startPoint . x  -  endPoint . x ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											var  y  =  endPoint . y  -  startPoint . y ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											var  r  =  Math . atan2 ( y ,  x ) ;  //radians
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											var  angle  =  Math . round ( r  *  180  /  Math . PI ) ;  //degrees
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											//ensure value is positive
 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( angle  <  0 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												angle  =  360  -  Math . abs ( angle ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											return  angle ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										*  Calcualte  the  direction  of  the  swipe 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										*  This  will  also  call  caluculateAngle  to  get  the  latest  angle  of  swipe 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										*  @ param  finger  A  finger  object  containing  start  and  end  points 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										* / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										function  calculateDirection ( startPoint ,  endPoint  )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											var  angle  =  caluculateAngle ( startPoint ,  endPoint ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( ( angle  <=  45 )  &&  ( angle  >=  0 ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												return  LEFT ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											}  else  if  ( ( angle  <=  360 )  &&  ( angle  >=  315 ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												return  LEFT ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											}  else  if  ( ( angle  >=  135 )  &&  ( angle  <=  225 ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												return  RIGHT ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											}  else  if  ( ( angle  >  45 )  &&  ( angle  <  135 ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												return  DOWN ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												return  UP ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										*  Returns  a  MS  time  stamp  of  the  current  time 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										* / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										function  getTimeStamp ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											var  now  =  new  Date ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  now . getTime ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										*  Removes  all  listeners  that  were  associated  with  the  plugin 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										* / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										function  removeListeners ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											$element . unbind ( START _EV ,  touchStart ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$element . unbind ( CANCEL _EV ,  touchCancel ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$element . unbind ( MOVE _EV ,  touchMove ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$element . unbind ( END _EV ,  touchEnd ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											setTouchInProgress ( false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 *  Returns  true  if  any  Pinch  events  have  been  registered 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										function  hasPinches ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  options . pinchStatus  ||  options . pinchIn  ||  options . pinchOut ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 *  Returns  true  if  we  are  detecting  pinches ,  and  have  one 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										function  didPinch ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  pinchDirection  &&  hasPinches ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										*  gets  a  data  flag  to  indicate  that  a  touch  is  in  progress 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										* / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										function  getTouchInProgress ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  $element . data ( PLUGIN _NS + '_intouch' )  ===  true  ?  true  :  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2012-06-13 15:16:43 +04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
									
										
										
										
											2012-12-19 06:23:50 +04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										*  Sets  a  data  flag  to  indicate  that  a  touch  is  in  progress 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										* / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										function  setTouchInProgress ( val )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											val  =  val === true ? true : false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$element . data ( PLUGIN _NS + '_intouch' ,  val ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										function  createFingerData ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											var  fingerData = [ ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											for  ( var  i = 0 ;  i <= 5 ;  i ++ )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												fingerData . push ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													start : {  x :  0 ,  y :  0  } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													end : {  x :  0 ,  y :  0  } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													delta : {  x :  0 ,  y :  0  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  fingerData ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ) ( jQuery ) ;