@@ -30,6 +30,7 @@ var VERSION = '1.2.2', $ = '$areaSortable',
3030 UNRESTRICTED = VERTICAL + HORIZONTAL ,
3131 stdMath = Math , Str = String , int = parseInt ,
3232 hasProp = Object . prototype . hasOwnProperty ,
33+ toString = Object . prototype . toString ,
3334 trim_re = / ^ \s + | \s + $ / g, mouse_evt = / m o u s e d o w n | p o i n t e r d o w n / ,
3435 trim = Str . prototype . trim
3536 ? function ( s ) { return s . trim ( ) ; }
@@ -48,6 +49,14 @@ function sign(x, signOfZero)
4849{
4950 return 0 > x ? - 1 : ( 0 < x ? 1 : ( signOfZero || 0 ) ) ;
5051}
52+ function is_callable ( x )
53+ {
54+ return 'function' === typeof x ;
55+ }
56+ function is_string ( x )
57+ {
58+ return '[object String]' === toString . call ( x ) ;
59+ }
5160function concat ( a )
5261{
5362 for ( var i = 1 , args = arguments , n = args . length ; i < n ; ++ i )
@@ -139,7 +148,7 @@ function canScroll(el, scrollAxis)
139148}
140149function computedStyle ( el )
141150{
142- return ( 'function' === typeof ( window . getComputedStyle ) ? window . getComputedStyle ( el , null ) : el . currentStyle ) || { } ;
151+ return ( is_callable ( window . getComputedStyle ) ? window . getComputedStyle ( el , null ) : el . currentStyle ) || { } ;
143152}
144153function elementsAt ( document , x , y )
145154{
@@ -885,20 +894,20 @@ function setup(self, TYPE)
885894 parent = dragged . parentNode ;
886895 if (
887896 ! parent
888- || ( ( 'string' === typeof ( self . options . container ) )
897+ || ( is_string ( self . options . container )
889898 && ( parent . id !== self . options . container ) )
890- || ( ( 'string' !== typeof ( self . options . container ) )
899+ || ( ! is_string ( self . options . container )
891900 && ( parent !== self . options . container ) )
892901 )
893902 {
894903 clear ( ) ;
895904 return ;
896905 }
897906
898- if ( 'function' === typeof self . options . onStart )
907+ if ( is_callable ( self . options . onStart ) )
899908 self . options . onStart ( dragged ) ;
900909
901- if ( 'function' === typeof self . options . itemFilter )
910+ if ( is_callable ( self . options . itemFilter ) )
902911 {
903912 dragged = self . options . itemFilter ( dragged ) ;
904913 if ( ! dragged )
@@ -945,7 +954,8 @@ function setup(self, TYPE)
945954 var actualDragMove = function ( ) {
946955 var hovered , p = 0.0 , Y , X , deltaX , deltaY , delta , centerX , centerY ,
947956 c = TOP , s = HEIGHT , zc = LEFT , zs = WIDTH , z ,
948- d = 25 , d1 , d2 , d3 , d4 , sx , sy , tX = 0 , tY = 0 ;
957+ d = 25 , d1 , d2 , d3 , d4 , sx , sy , tX = 0 , tY = 0 ,
958+ changedDirX = false , changedDirY = false ;
949959
950960 if ( VERTICAL === TYPE )
951961 {
@@ -969,14 +979,16 @@ function setup(self, TYPE)
969979 {
970980 dragged [ $ ] . r [ TOP ] = lastY - Y0 + dragged [ $ ] [ RECT ] [ TOP ] ;
971981 dragged [ STYLE ] [ TOP ] = Str ( dragged [ $ ] . r [ TOP ] - parent [ $ ] [ RECT ] [ TOP ] + parent [ $ ] [ SCROLL ] [ TOP ] - dragged [ $ ] [ MARGIN ] [ TOP ] + scroll [ TOP ] ) + 'px' ;
982+ changedDirY = 0 > deltaY * lastDeltaY ;
972983 }
973984 if ( VERTICAL !== TYPE )
974985 {
975986 dragged [ $ ] . r [ LEFT ] = lastX - X0 + dragged [ $ ] [ RECT ] [ LEFT ] ;
976987 dragged [ STYLE ] [ LEFT ] = Str ( dragged [ $ ] . r [ LEFT ] - parent [ $ ] [ RECT ] [ LEFT ] + parent [ $ ] [ SCROLL ] [ LEFT ] - dragged [ $ ] [ MARGIN ] [ LEFT ] + scroll [ LEFT ] ) + 'px' ;
988+ changedDirX = 0 > deltaX * lastDeltaX ;
977989 }
978990
979- if ( self . options . autoscroll && scrollParent && ( ! scrolling || 0 > deltaX * lastDeltaX || 0 > deltaY * lastDeltaY ) )
991+ if ( self . options . autoscroll && scrollParent && ( ! scrolling || changedDirX || changedDirY ) )
980992 {
981993 if ( scrolling )
982994 {
@@ -989,17 +1001,17 @@ function setup(self, TYPE)
9891001 d2 = 0 ;
9901002 d3 = scrollParent [ $ ] [ RECT ] [ HEIGHT ] ;
9911003 d4 = 0 ;
992- sx = 2 ;
993- sy = 2 ;
1004+ sx = 1.5 ;
1005+ sy = 1.5 ;
9941006 }
9951007 else
9961008 {
9971009 d1 = scrollParent [ $ ] [ RECT ] [ RIGHT ] ;
9981010 d2 = scrollParent [ $ ] [ RECT ] [ LEFT ] ;
9991011 d3 = scrollParent [ $ ] [ RECT ] [ BOTTOM ] ;
10001012 d4 = scrollParent [ $ ] [ RECT ] [ TOP ] ;
1001- sx = 1.5 ;
1002- sy = 1.5 ;
1013+ sx = 1.2 ;
1014+ sy = 1.2 ;
10031015 }
10041016 if (
10051017 ( VERTICAL !== TYPE )
@@ -1034,7 +1046,7 @@ function setup(self, TYPE)
10341046 sL += vX * dt ;
10351047 scrollParent [ STOP ] = stdMath . min ( stdMath . max ( 0 , sT ) , scrollParent [ $ ] [ SCROLL ] [ HEIGHT ] - scrollParent [ $ ] [ RECT ] [ HEIGHT ] ) ;
10361048 scrollParent [ SLEFT ] = stdMath . min ( stdMath . max ( 0 , sL ) , scrollParent [ $ ] [ SCROLL ] [ WIDTH ] - scrollParent [ $ ] [ RECT ] [ WIDTH ] ) ;
1037- if ( duration >= tS )
1049+ if ( scrolling && ( duration >= tS ) )
10381050 {
10391051 clearInterval ( scrolling ) ;
10401052 scrolling = null ;
@@ -1169,7 +1181,7 @@ function setup(self, TYPE)
11691181 var el = dragged ;
11701182 restore ( ) ;
11711183 clear ( ) ;
1172- if ( 'function' === typeof self . options . onEnd )
1184+ if ( is_callable ( self . options . onEnd ) )
11731185 self . options . onEnd ( el ) ;
11741186 } ;
11751187
@@ -1194,9 +1206,9 @@ function setup(self, TYPE)
11941206 canHandle = false ;
11951207 if ( attached )
11961208 {
1197- attached = false ;
11981209 removeEvent ( document , 'touchstart' , dragStart , { capture :true , passive :false } ) ;
11991210 removeEvent ( document , 'mousedown' , dragStart , { capture :true , passive :false } ) ;
1211+ attached = false ;
12001212 }
12011213 restore ( ) ;
12021214 clear ( ) ;
0 commit comments