@@ -30,6 +30,7 @@ var VERSION = '1.2.2', $ = '$areaSortable',
30
30
UNRESTRICTED = VERTICAL + HORIZONTAL ,
31
31
stdMath = Math , Str = String , int = parseInt ,
32
32
hasProp = Object . prototype . hasOwnProperty ,
33
+ toString = Object . prototype . toString ,
33
34
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 / ,
34
35
trim = Str . prototype . trim
35
36
? function ( s ) { return s . trim ( ) ; }
@@ -48,6 +49,14 @@ function sign(x, signOfZero)
48
49
{
49
50
return 0 > x ? - 1 : ( 0 < x ? 1 : ( signOfZero || 0 ) ) ;
50
51
}
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
+ }
51
60
function concat ( a )
52
61
{
53
62
for ( var i = 1 , args = arguments , n = args . length ; i < n ; ++ i )
@@ -139,7 +148,7 @@ function canScroll(el, scrollAxis)
139
148
}
140
149
function computedStyle ( el )
141
150
{
142
- return ( 'function' === typeof ( window . getComputedStyle ) ? window . getComputedStyle ( el , null ) : el . currentStyle ) || { } ;
151
+ return ( is_callable ( window . getComputedStyle ) ? window . getComputedStyle ( el , null ) : el . currentStyle ) || { } ;
143
152
}
144
153
function elementsAt ( document , x , y )
145
154
{
@@ -885,20 +894,20 @@ function setup(self, TYPE)
885
894
parent = dragged . parentNode ;
886
895
if (
887
896
! parent
888
- || ( ( 'string' === typeof ( self . options . container ) )
897
+ || ( is_string ( self . options . container )
889
898
&& ( parent . id !== self . options . container ) )
890
- || ( ( 'string' !== typeof ( self . options . container ) )
899
+ || ( ! is_string ( self . options . container )
891
900
&& ( parent !== self . options . container ) )
892
901
)
893
902
{
894
903
clear ( ) ;
895
904
return ;
896
905
}
897
906
898
- if ( 'function' === typeof self . options . onStart )
907
+ if ( is_callable ( self . options . onStart ) )
899
908
self . options . onStart ( dragged ) ;
900
909
901
- if ( 'function' === typeof self . options . itemFilter )
910
+ if ( is_callable ( self . options . itemFilter ) )
902
911
{
903
912
dragged = self . options . itemFilter ( dragged ) ;
904
913
if ( ! dragged )
@@ -945,7 +954,8 @@ function setup(self, TYPE)
945
954
var actualDragMove = function ( ) {
946
955
var hovered , p = 0.0 , Y , X , deltaX , deltaY , delta , centerX , centerY ,
947
956
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 ;
949
959
950
960
if ( VERTICAL === TYPE )
951
961
{
@@ -969,14 +979,16 @@ function setup(self, TYPE)
969
979
{
970
980
dragged [ $ ] . r [ TOP ] = lastY - Y0 + dragged [ $ ] [ RECT ] [ TOP ] ;
971
981
dragged [ STYLE ] [ TOP ] = Str ( dragged [ $ ] . r [ TOP ] - parent [ $ ] [ RECT ] [ TOP ] + parent [ $ ] [ SCROLL ] [ TOP ] - dragged [ $ ] [ MARGIN ] [ TOP ] + scroll [ TOP ] ) + 'px' ;
982
+ changedDirY = 0 > deltaY * lastDeltaY ;
972
983
}
973
984
if ( VERTICAL !== TYPE )
974
985
{
975
986
dragged [ $ ] . r [ LEFT ] = lastX - X0 + dragged [ $ ] [ RECT ] [ LEFT ] ;
976
987
dragged [ STYLE ] [ LEFT ] = Str ( dragged [ $ ] . r [ LEFT ] - parent [ $ ] [ RECT ] [ LEFT ] + parent [ $ ] [ SCROLL ] [ LEFT ] - dragged [ $ ] [ MARGIN ] [ LEFT ] + scroll [ LEFT ] ) + 'px' ;
988
+ changedDirX = 0 > deltaX * lastDeltaX ;
977
989
}
978
990
979
- if ( self . options . autoscroll && scrollParent && ( ! scrolling || 0 > deltaX * lastDeltaX || 0 > deltaY * lastDeltaY ) )
991
+ if ( self . options . autoscroll && scrollParent && ( ! scrolling || changedDirX || changedDirY ) )
980
992
{
981
993
if ( scrolling )
982
994
{
@@ -989,17 +1001,17 @@ function setup(self, TYPE)
989
1001
d2 = 0 ;
990
1002
d3 = scrollParent [ $ ] [ RECT ] [ HEIGHT ] ;
991
1003
d4 = 0 ;
992
- sx = 2 ;
993
- sy = 2 ;
1004
+ sx = 1.5 ;
1005
+ sy = 1.5 ;
994
1006
}
995
1007
else
996
1008
{
997
1009
d1 = scrollParent [ $ ] [ RECT ] [ RIGHT ] ;
998
1010
d2 = scrollParent [ $ ] [ RECT ] [ LEFT ] ;
999
1011
d3 = scrollParent [ $ ] [ RECT ] [ BOTTOM ] ;
1000
1012
d4 = scrollParent [ $ ] [ RECT ] [ TOP ] ;
1001
- sx = 1.5 ;
1002
- sy = 1.5 ;
1013
+ sx = 1.2 ;
1014
+ sy = 1.2 ;
1003
1015
}
1004
1016
if (
1005
1017
( VERTICAL !== TYPE )
@@ -1034,7 +1046,7 @@ function setup(self, TYPE)
1034
1046
sL += vX * dt ;
1035
1047
scrollParent [ STOP ] = stdMath . min ( stdMath . max ( 0 , sT ) , scrollParent [ $ ] [ SCROLL ] [ HEIGHT ] - scrollParent [ $ ] [ RECT ] [ HEIGHT ] ) ;
1036
1048
scrollParent [ SLEFT ] = stdMath . min ( stdMath . max ( 0 , sL ) , scrollParent [ $ ] [ SCROLL ] [ WIDTH ] - scrollParent [ $ ] [ RECT ] [ WIDTH ] ) ;
1037
- if ( duration >= tS )
1049
+ if ( scrolling && ( duration >= tS ) )
1038
1050
{
1039
1051
clearInterval ( scrolling ) ;
1040
1052
scrolling = null ;
@@ -1169,7 +1181,7 @@ function setup(self, TYPE)
1169
1181
var el = dragged ;
1170
1182
restore ( ) ;
1171
1183
clear ( ) ;
1172
- if ( 'function' === typeof self . options . onEnd )
1184
+ if ( is_callable ( self . options . onEnd ) )
1173
1185
self . options . onEnd ( el ) ;
1174
1186
} ;
1175
1187
@@ -1194,9 +1206,9 @@ function setup(self, TYPE)
1194
1206
canHandle = false ;
1195
1207
if ( attached )
1196
1208
{
1197
- attached = false ;
1198
1209
removeEvent ( document , 'touchstart' , dragStart , { capture :true , passive :false } ) ;
1199
1210
removeEvent ( document , 'mousedown' , dragStart , { capture :true , passive :false } ) ;
1211
+ attached = false ;
1200
1212
}
1201
1213
restore ( ) ;
1202
1214
clear ( ) ;
0 commit comments