@@ -1112,7 +1112,8 @@ colors = jQuery.Color.names = {
11121112
11131113
11141114! function ( $ , window , undefined ) {
1115- var pluginName = 'sortable' ,
1115+ var eventNames ,
1116+ pluginName = 'sortable' ,
11161117 document = window . document ,
11171118 $document = $ ( document ) ,
11181119 containerDefaults = {
@@ -1171,6 +1172,20 @@ colors = jQuery.Color.names = {
11711172 containerGroups = { } ,
11721173 groupCounter = 0
11731174
1175+ if ( 'ontouchstart' in window ) {
1176+ eventNames = {
1177+ start : "touchstart" ,
1178+ end : "touchend" ,
1179+ move : "touchmove"
1180+ }
1181+ } else {
1182+ eventNames = {
1183+ start : "mousedown" ,
1184+ end : "mouseup" ,
1185+ move : "mousemove"
1186+ }
1187+ }
1188+
11741189 /*
11751190 * a is Array [left, right, top, bottom]
11761191 * b is array [left, top]
@@ -1247,7 +1262,7 @@ colors = jQuery.Color.names = {
12471262 this . options = $ . extend ( { } , groupDefaults , options )
12481263 this . containers = [ ]
12491264 this . childGroups = [ ]
1250- this . scrollProxy = $ . proxy ( this . scrolled , this )
1265+ this . scrolledProxy = $ . proxy ( this . scrolled , this )
12511266 this . dragProxy = $ . proxy ( this . drag , this )
12521267 this . dropProxy = $ . proxy ( this . drop , this )
12531268 if ( this . options . parentGroup )
@@ -1267,8 +1282,9 @@ colors = jQuery.Color.names = {
12671282
12681283 ContainerGroup . prototype = {
12691284 dragInit : function ( e , itemContainer ) {
1270- $document . on ( "mousemove" , this . dragProxy )
1271- $document . on ( "mouseup" , this . dropProxy )
1285+ $document . on ( eventNames . move + "." + pluginName , this . dragProxy )
1286+ $document . on ( eventNames . end + "." + pluginName , this . dropProxy )
1287+ $document . on ( "scroll." + pluginName , this . scrolledProxy )
12721288
12731289 // get item to drag
12741290 this . item = $ ( e . target ) . closest ( this . options . itemSelector )
@@ -1303,8 +1319,9 @@ colors = jQuery.Color.names = {
13031319 drop : function ( e ) {
13041320 e . preventDefault ( )
13051321
1306- $document . off ( "mousemove" , this . dragProxy )
1307- $document . off ( "mouseup" , this . dropProxy )
1322+ $document . off ( eventNames . move + "." + pluginName )
1323+ $document . off ( eventNames . end + "." + pluginName )
1324+ $document . off ( "scroll." + pluginName )
13081325
13091326 if ( ! this . dragging )
13101327 return ;
@@ -1314,7 +1331,8 @@ colors = jQuery.Color.names = {
13141331 processChildContainers ( this . item , this . options . containerSelector , "enable" , true )
13151332
13161333 // cleanup
1317- this . deleteDimensions ( )
1334+ this . clearDimensions ( )
1335+ this . clearOffsetParent ( )
13181336 this . lastAppendedItem = this . sameResultBox = undefined
13191337 this . dragging = false
13201338 } ,
@@ -1351,9 +1369,12 @@ colors = jQuery.Color.names = {
13511369 } ,
13521370 getContainerDimensions : function ( ) {
13531371 if ( ! this . containerDimensions )
1354- setDimensions ( this . containers , this . containerDimensions = [ ] , ! this . getOffsetParent ( ) )
1372+ setDimensions ( this . getContainers ( ) , this . containerDimensions = [ ] , ! this . getOffsetParent ( ) )
13551373 return this . containerDimensions
13561374 } ,
1375+ getContainers : function ( element ) { // TODO build on this to return containers valid for the currently dragged element
1376+ return this . containers
1377+ } ,
13571378 getContainer : function ( element ) {
13581379 return element . closest ( this . options . containerSelector ) . data ( pluginName )
13591380 } ,
@@ -1362,20 +1383,26 @@ colors = jQuery.Color.names = {
13621383 var i = this . containers . length - 1 ,
13631384 offsetParent = this . containers [ i ] . getItemOffsetParent ( )
13641385
1365- while ( i -- ) {
1366- if ( offsetParent [ 0 ] != this . containers [ i ] . getItemOffsetParent ( ) [ 0 ] ) {
1367- // If every container has the same offset parent,
1368- // use position() which is relative to this parent,
1369- // otherwise use offset()
1370- $document . on ( "scroll" , this . scrolledProxy )
1371- offsetParent = false
1372- break ;
1386+ if ( ! this . options . parentGroup ) {
1387+ while ( i -- ) {
1388+ if ( offsetParent [ 0 ] != this . containers [ i ] . getItemOffsetParent ( ) [ 0 ] ) {
1389+ // If every container has the same offset parent,
1390+ // use position() which is relative to this parent,
1391+ // otherwise use offset()
1392+ // compare #setDimensions
1393+ offsetParent = false
1394+ break ;
1395+ }
13731396 }
13741397 }
1398+
13751399 this . offsetParent = offsetParent
13761400 }
13771401 return this . offsetParent
13781402 } ,
1403+ clearOffsetParent : function ( ) {
1404+ this . offsetParent = undefined
1405+ } ,
13791406 setPointer : function ( e ) {
13801407 var pointer = {
13811408 left : e . pageX ,
@@ -1394,26 +1421,25 @@ colors = jQuery.Color.names = {
13941421 } ,
13951422 addContainer : function ( container ) {
13961423 this . containers . push ( container ) ;
1397- delete this . containerDimensions
13981424 } ,
13991425 removeContainer : function ( container ) {
14001426 var i = this . containers . indexOf ( container )
14011427 this . containers . remove ( i ) ;
1402- delete this . containerDimensions
14031428 } ,
14041429 scrolled : function ( e ) {
1405- delete this . containerDimensions
1430+ this . clearDimensions ( )
1431+ this . clearOffsetParent ( )
14061432 } ,
1407- deleteDimensions : function ( ) {
1408- // delete centers in every container and containergroup
1409- delete this . containerDimensions
1433+ // Recursively clear container and item dimensions
1434+ clearDimensions : function ( ) {
1435+ this . containerDimensions = undefined
14101436 var i = this . containers . length
14111437 while ( i -- ) {
1412- delete this . containers [ i ] . itemDimensions
1438+ this . containers [ i ] . itemDimensions = undefined
14131439 }
14141440 i = this . childGroups . length
14151441 while ( i -- ) {
1416- this . childGroups [ i ] . deleteDimensions ( )
1442+ this . childGroups [ i ] . clearDimensions ( )
14171443 }
14181444 }
14191445 }
@@ -1515,7 +1541,7 @@ colors = jQuery.Color.names = {
15151541 el = this . el
15161542 // Since el might be empty we have to check el itself and
15171543 // can not do something like el.children().first().offsetParent()
1518- if ( el . css ( "position" ) === "relative" || el . css ( "position" ) === "absolute" )
1544+ if ( el . css ( "position" ) === "relative" || el . css ( "position" ) === "absolute" || el . css ( "position" ) === "fixed" )
15191545 offsetParent = el
15201546 else
15211547 offsetParent = el . offsetParent ( )
@@ -1546,15 +1572,15 @@ colors = jQuery.Color.names = {
15461572 this . group . addContainer ( this )
15471573 if ( ! ignoreChildren )
15481574 processChildContainers ( this . el , this . options . containerSelector , "enable" , true )
1549- this . el . on ( "mousedown" , this . handle , this . dragInitProxy )
1575+ this . el . on ( eventNames . start + "." + pluginName , this . handle , this . dragInitProxy )
15501576 } ,
15511577 disable : function ( ignoreChildren ) {
15521578 if ( this . options . drop )
15531579 this . group . removeContainer ( this )
15541580 if ( ! ignoreChildren )
15551581 processChildContainers ( this . el , this . options . containerSelector , "disable" , true )
15561582
1557- this . el . off ( "mousedown" , this . handle , this . dragInitProxy )
1583+ this . el . off ( eventNames . start + "." + pluginName , this . handle , this . dragInitProxy )
15581584 }
15591585 }
15601586
0 commit comments