@ -56,7 +56,8 @@
moved ,
moved ,
/** @const */
/** @const */
RSPACE = /\s+/g ,
R _SPACE = /\s+/g ,
R _FLOAT = /left|right|inline/ ,
expando = 'Sortable' + ( new Date ) . getTime ( ) ,
expando = 'Sortable' + ( new Date ) . getTime ( ) ,
@ -67,7 +68,7 @@
$ = win . jQuery || win . Zepto ,
$ = win . jQuery || win . Zepto ,
Polymer = win . Polymer ,
Polymer = win . Polymer ,
captureMode = { capture : false , passive : false } ,
captureMode = false ,
supportDraggable = ! ! ( 'draggable' in document . createElement ( 'div' ) ) ,
supportDraggable = ! ! ( 'draggable' in document . createElement ( 'div' ) ) ,
supportCssPointerEvents = ( function ( el ) {
supportCssPointerEvents = ( function ( el ) {
@ -85,6 +86,7 @@
abs = Math . abs ,
abs = Math . abs ,
min = Math . min ,
min = Math . min ,
savedInputChecked = [ ] ,
touchDragOverListeners = [ ] ,
touchDragOverListeners = [ ] ,
_autoScroll = _throttle ( function ( /**Event*/ evt , /**Object*/ options , /**HTMLElement*/ rootEl ) {
_autoScroll = _throttle ( function ( /**Event*/ evt , /**Object*/ options , /**HTMLElement*/ rootEl ) {
@ -213,7 +215,6 @@
;
;
/ * *
/ * *
* @ class Sortable
* @ class Sortable
* @ param { HTMLElement } el
* @ param { HTMLElement } el
@ -231,7 +232,6 @@
// Export instance
// Export instance
el [ expando ] = this ;
el [ expando ] = this ;
// Default options
// Default options
var defaults = {
var defaults = {
group : Math . random ( ) ,
group : Math . random ( ) ,
@ -314,6 +314,9 @@
filter = options . filter ,
filter = options . filter ,
startIndex ;
startIndex ;
_saveInputCheckedState ( el ) ;
// Don't trigger start event when an element is been dragged, otherwise the evt.oldindex always wrong when set option.group.
// Don't trigger start event when an element is been dragged, otherwise the evt.oldindex always wrong when set option.group.
if ( dragEl ) {
if ( dragEl ) {
return ;
return ;
@ -420,6 +423,7 @@
_on ( ownerDocument , 'touchend' , _this . _onDrop ) ;
_on ( ownerDocument , 'touchend' , _this . _onDrop ) ;
_on ( ownerDocument , 'touchcancel' , _this . _onDrop ) ;
_on ( ownerDocument , 'touchcancel' , _this . _onDrop ) ;
_on ( ownerDocument , 'pointercancel' , _this . _onDrop ) ;
_on ( ownerDocument , 'pointercancel' , _this . _onDrop ) ;
_on ( ownerDocument , 'selectstart' , _this ) ;
if ( options . delay ) {
if ( options . delay ) {
// If the user moves the pointer or let go the click or touch
// If the user moves the pointer or let go the click or touch
@ -437,9 +441,7 @@
dragStartFn ( ) ;
dragStartFn ( ) ;
}
}
if ( options . forceFallback ) {
evt . preventDefault ( ) ;
}
}
}
} ,
} ,
@ -457,6 +459,7 @@
_triggerDragStart : function ( /** Event */ evt , /** Touch */ touch ) {
_triggerDragStart : function ( /** Event */ evt , /** Touch */ touch ) {
touch = touch || ( evt . pointerType == 'touch' ? evt : null ) ;
touch = touch || ( evt . pointerType == 'touch' ? evt : null ) ;
if ( touch ) {
if ( touch ) {
// Touch device support
// Touch device support
tapEvt = {
tapEvt = {
@ -675,6 +678,7 @@
group = options . group ,
group = options . group ,
activeSortable = Sortable . active ,
activeSortable = Sortable . active ,
isOwner = ( activeGroup === group ) ,
isOwner = ( activeGroup === group ) ,
isMovingBetweenSortable = false ,
canSort = options . sort ;
canSort = options . sort ;
if ( evt . preventDefault !== void 0 ) {
if ( evt . preventDefault !== void 0 ) {
@ -682,6 +686,10 @@
! options . dragoverBubble && evt . stopPropagation ( ) ;
! options . dragoverBubble && evt . stopPropagation ( ) ;
}
}
if ( dragEl . animated ) {
return ;
}
moved = true ;
moved = true ;
if ( activeSortable && ! options . disabled &&
if ( activeSortable && ! options . disabled &&
@ -706,7 +714,11 @@
target = _closest ( evt . target , options . draggable , el ) ;
target = _closest ( evt . target , options . draggable , el ) ;
dragRect = dragEl . getBoundingClientRect ( ) ;
dragRect = dragEl . getBoundingClientRect ( ) ;
putSortable = this ;
if ( putSortable !== this ) {
putSortable = this ;
isMovingBetweenSortable = true ;
}
if ( revert ) {
if ( revert ) {
_cloneHide ( activeSortable , true ) ;
_cloneHide ( activeSortable , true ) ;
@ -762,14 +774,14 @@
var width = targetRect . right - targetRect . left ,
var width = targetRect . right - targetRect . left ,
height = targetRect . bottom - targetRect . top ,
height = targetRect . bottom - targetRect . top ,
floating = /left|right|inline/ . test ( lastCSS . cssFloat + lastCSS . display )
floating = R _FLOAT . test ( lastCSS . cssFloat + lastCSS . display )
|| ( lastParentCSS . display == 'flex' && lastParentCSS [ 'flex-direction' ] . indexOf ( 'row' ) === 0 ) ,
|| ( lastParentCSS . display == 'flex' && lastParentCSS [ 'flex-direction' ] . indexOf ( 'row' ) === 0 ) ,
isWide = ( target . offsetWidth > dragEl . offsetWidth ) ,
isWide = ( target . offsetWidth > dragEl . offsetWidth ) ,
isLong = ( target . offsetHeight > dragEl . offsetHeight ) ,
isLong = ( target . offsetHeight > dragEl . offsetHeight ) ,
halfway = ( floating ? ( evt . clientX - targetRect . left ) / width : ( evt . clientY - targetRect . top ) / height ) > 0.5 ,
halfway = ( floating ? ( evt . clientX - targetRect . left ) / width : ( evt . clientY - targetRect . top ) / height ) > 0.5 ,
nextSibling = target . nextElementSibling ,
nextSibling = target . nextElementSibling ,
moveVector = _onMove ( rootEl , el , dragEl , dragRect , target , targetRect , evt ) ,
moveVector = _onMove ( rootEl , el , dragEl , dragRect , target , targetRect , evt ) ,
after
after = false
;
;
if ( moveVector !== false ) {
if ( moveVector !== false ) {
@ -793,7 +805,7 @@
} else {
} else {
after = tgTop > elTop ;
after = tgTop > elTop ;
}
}
} else {
} else if ( ! isMovingBetweenSortable ) {
after = ( nextSibling !== dragEl ) && ! isLong || halfway && isLong ;
after = ( nextSibling !== dragEl ) && ! isLong || halfway && isLong ;
}
}
@ -853,6 +865,7 @@
_off ( ownerDocument , 'touchend' , this . _onDrop ) ;
_off ( ownerDocument , 'touchend' , this . _onDrop ) ;
_off ( ownerDocument , 'pointerup' , this . _onDrop ) ;
_off ( ownerDocument , 'pointerup' , this . _onDrop ) ;
_off ( ownerDocument , 'touchcancel' , this . _onDrop ) ;
_off ( ownerDocument , 'touchcancel' , this . _onDrop ) ;
_off ( ownerDocument , 'selectstart' , this ) ;
} ,
} ,
_onDrop : function ( /**Event*/ evt ) {
_onDrop : function ( /**Event*/ evt ) {
@ -881,6 +894,11 @@
ghostEl && ghostEl . parentNode . removeChild ( ghostEl ) ;
ghostEl && ghostEl . parentNode . removeChild ( ghostEl ) ;
if ( rootEl === parentEl || Sortable . active . lastPullMode !== 'clone' ) {
// Remove clone
cloneEl && cloneEl . parentNode . removeChild ( cloneEl ) ;
}
if ( dragEl ) {
if ( dragEl ) {
if ( this . nativeDraggable ) {
if ( this . nativeDraggable ) {
_off ( dragEl , 'dragend' , this ) ;
_off ( dragEl , 'dragend' , this ) ;
@ -900,7 +918,6 @@
newIndex = _index ( dragEl , options . draggable ) ;
newIndex = _index ( dragEl , options . draggable ) ;
if ( newIndex >= 0 ) {
if ( newIndex >= 0 ) {
// Add event
// Add event
_dispatchEvent ( null , parentEl , 'add' , dragEl , rootEl , oldIndex , newIndex ) ;
_dispatchEvent ( null , parentEl , 'add' , dragEl , rootEl , oldIndex , newIndex ) ;
@ -913,9 +930,6 @@
}
}
}
}
else {
else {
// Remove clone
cloneEl && cloneEl . parentNode . removeChild ( cloneEl ) ;
if ( dragEl . nextSibling !== nextEl ) {
if ( dragEl . nextSibling !== nextEl ) {
// Get the index of the dragged element within its parent
// Get the index of the dragged element within its parent
newIndex = _index ( dragEl , options . draggable ) ;
newIndex = _index ( dragEl , options . draggable ) ;
@ -970,19 +984,31 @@
putSortable =
putSortable =
activeGroup =
activeGroup =
Sortable . active = null ;
Sortable . active = null ;
savedInputChecked . forEach ( function ( el ) {
el . checked = true ;
} ) ;
savedInputChecked . length = 0 ;
} ,
} ,
handleEvent : function ( /**Event*/ evt ) {
handleEvent : function ( /**Event*/ evt ) {
var type = evt . type ;
switch ( evt . type ) {
case 'drop' :
case 'dragend' :
this . _onDrop ( evt ) ;
break ;
case 'dragover' :
case 'dragenter' :
if ( dragEl ) {
this . _onDragOver ( evt ) ;
_globalDragOver ( evt ) ;
}
break ;
if ( type === 'dragover' || type === 'dragenter' ) {
case 'selectstart' :
if ( dragEl ) {
evt . preventDefault ( ) ;
this . _onDragOver ( evt ) ;
break ;
_globalDragOver ( evt ) ;
}
}
else if ( type === 'drop' || type === 'dragend' ) {
this . _onDrop ( evt ) ;
}
}
} ,
} ,
@ -1177,8 +1203,8 @@
el . classList [ state ? 'add' : 'remove' ] ( name ) ;
el . classList [ state ? 'add' : 'remove' ] ( name ) ;
}
}
else {
else {
var className = ( ' ' + el . className + ' ' ) . replace ( RSPACE , ' ' ) . replace ( ' ' + name + ' ' , ' ' ) ;
var className = ( ' ' + el . className + ' ' ) . replace ( R _ SPACE, ' ' ) . replace ( ' ' + name + ' ' , ' ' ) ;
el . className = ( className + ( state ? ' ' + name : '' ) ) . replace ( RSPACE , ' ' ) ;
el . className = ( className + ( state ? ' ' + name : '' ) ) . replace ( R _ SPACE, ' ' ) ;
}
}
}
}
}
}
@ -1399,6 +1425,34 @@
) ;
) ;
}
}
function _saveInputCheckedState ( root ) {
var inputs = root . getElementsByTagName ( 'input' ) ;
var idx = inputs . length ;
while ( idx -- ) {
var el = inputs [ idx ] ;
el . checked && savedInputChecked . push ( el ) ;
}
}
// Fixed #973:
_on ( document , 'touchmove' , function ( evt ) {
if ( Sortable . active ) {
evt . preventDefault ( ) ;
}
} ) ;
try {
window . addEventListener ( 'test' , null , Object . defineProperty ( { } , 'passive' , {
get : function ( ) {
captureMode = {
capture : false ,
passive : false
} ;
}
} ) ) ;
} catch ( err ) { }
// Export utils
// Export utils
Sortable . utils = {
Sortable . utils = {
on : _on ,
on : _on ,
@ -1428,6 +1482,6 @@
// Export
// Export
Sortable . version = '1.5.0-rc 1' ;
Sortable . version = '1.5.1' ;
return Sortable ;
return Sortable ;
} ) ;
} ) ;