@ -56,7 +56,8 @@
moved ,
/** @const */
RSPACE = /\s+/g ,
R _SPACE = /\s+/g ,
R _FLOAT = /left|right|inline/ ,
expando = 'Sortable' + ( new Date ) . getTime ( ) ,
@ -67,7 +68,7 @@
$ = win . jQuery || win . Zepto ,
Polymer = win . Polymer ,
captureMode = { capture : false , passive : false } ,
captureMode = false ,
supportDraggable = ! ! ( 'draggable' in document . createElement ( 'div' ) ) ,
supportCssPointerEvents = ( function ( el ) {
@ -85,6 +86,7 @@
abs = Math . abs ,
min = Math . min ,
savedInputChecked = [ ] ,
touchDragOverListeners = [ ] ,
_autoScroll = _throttle ( function ( /**Event*/ evt , /**Object*/ options , /**HTMLElement*/ rootEl ) {
@ -213,7 +215,6 @@
;
/ * *
* @ class Sortable
* @ param { HTMLElement } el
@ -231,7 +232,6 @@
// Export instance
el [ expando ] = this ;
// Default options
var defaults = {
group : Math . random ( ) ,
@ -314,6 +314,9 @@
filter = options . filter ,
startIndex ;
_saveInputCheckedState ( el ) ;
// Don't trigger start event when an element is been dragged, otherwise the evt.oldindex always wrong when set option.group.
if ( dragEl ) {
return ;
@ -384,7 +387,7 @@
dragEl = target ;
parentEl = dragEl . parentNode ;
nextEl = dragEl . nextSibling ;
lastDownEl = target
lastDownEl = target ;
activeGroup = options . group ;
oldIndex = startIndex ;
@ -420,6 +423,7 @@
_on ( ownerDocument , 'touchend' , _this . _onDrop ) ;
_on ( ownerDocument , 'touchcancel' , _this . _onDrop ) ;
_on ( ownerDocument , 'pointercancel' , _this . _onDrop ) ;
_on ( ownerDocument , 'selectstart' , _this ) ;
if ( options . delay ) {
// If the user moves the pointer or let go the click or touch
@ -437,9 +441,7 @@
dragStartFn ( ) ;
}
if ( options . forceFallback ) {
evt . preventDefault ( ) ;
}
}
} ,
@ -457,6 +459,7 @@
_triggerDragStart : function ( /** Event */ evt , /** Touch */ touch ) {
touch = touch || ( evt . pointerType == 'touch' ? evt : null ) ;
if ( touch ) {
// Touch device support
tapEvt = {
@ -476,11 +479,11 @@
}
try {
if ( document . selection ) {
// Timeout neccessary for IE9
if ( document . selection ) {
// Timeout neccessary for IE9
setTimeout ( function ( ) {
document . selection . empty ( ) ;
} ) ;
} ) ;
} else {
window . getSelection ( ) . removeAllRanges ( ) ;
}
@ -675,6 +678,7 @@
group = options . group ,
activeSortable = Sortable . active ,
isOwner = ( activeGroup === group ) ,
isMovingBetweenSortable = false ,
canSort = options . sort ;
if ( evt . preventDefault !== void 0 ) {
@ -682,6 +686,10 @@
! options . dragoverBubble && evt . stopPropagation ( ) ;
}
if ( dragEl . animated ) {
return ;
}
moved = true ;
if ( activeSortable && ! options . disabled &&
@ -706,7 +714,11 @@
target = _closest ( evt . target , options . draggable , el ) ;
dragRect = dragEl . getBoundingClientRect ( ) ;
putSortable = this ;
if ( putSortable !== this ) {
putSortable = this ;
isMovingBetweenSortable = true ;
}
if ( revert ) {
_cloneHide ( activeSortable , true ) ;
@ -724,8 +736,13 @@
if ( ( el . children . length === 0 ) || ( el . children [ 0 ] === ghostEl ) ||
( el === evt . target ) && ( target = _ghostIsLast ( el , evt ) )
( el === evt . target ) && ( _ghostIsLast ( el , evt ) )
) {
//assign target only if condition is true
if ( el . children . length !== 0 && el . children [ 0 ] !== ghostEl && el === evt . target ) {
target = el . lastElementChild ;
}
if ( target ) {
if ( target . animated ) {
return ;
@ -757,40 +774,42 @@
var width = targetRect . right - targetRect . left ,
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 ) ,
isWide = ( target . offsetWidth > dragEl . offsetWidth ) ,
isLong = ( target . offsetHeight > dragEl . offsetHeight ) ,
halfway = ( floating ? ( evt . clientX - targetRect . left ) / width : ( evt . clientY - targetRect . top ) / height ) > 0.5 ,
nextSibling = target . nextElementSibling ,
moveVector = _onMove ( rootEl , el , dragEl , dragRect , target , targetRect , evt ) ,
after
after = false
;
if ( moveVector !== false ) {
_silent = true ;
setTimeout ( _unsilent , 30 ) ;
if ( floating ) {
var elTop = dragEl . offsetTop ,
tgTop = target . offsetTop ;
_cloneHide ( activeSortable , isOwner ) ;
if ( elTop === tgTop ) {
after = ( target . previousElementSibling === dragEl ) && ! isWide || halfway && isWide ;
}
else if ( target . previousElementSibling === dragEl || dragEl . previousElementSibling === target ) {
after = ( evt . clientY - targetRect . top ) / height > 0.5 ;
} else {
after = tgTop > elTop ;
}
} else if ( ! isMovingBetweenSortable ) {
after = ( nextSibling !== dragEl ) && ! isLong || halfway && isLong ;
}
var moveVector = _onMove ( rootEl , el , dragEl , dragRect , target , targetRect , evt , after ) ;
if ( moveVector !== false ) {
if ( moveVector === 1 || moveVector === - 1 ) {
after = ( moveVector === 1 ) ;
}
else if ( floating ) {
var elTop = dragEl . offsetTop ,
tgTop = target . offsetTop ;
if ( elTop === tgTop ) {
after = ( target . previousElementSibling === dragEl ) && ! isWide || halfway && isWide ;
}
else if ( target . previousElementSibling === dragEl || dragEl . previousElementSibling === target ) {
after = ( evt . clientY - targetRect . top ) / height > 0.5 ;
} else {
after = tgTop > elTop ;
}
} else {
after = ( nextSibling !== dragEl ) && ! isLong || halfway && isLong ;
}
_silent = true ;
setTimeout ( _unsilent , 30 ) ;
_cloneHide ( activeSortable , isOwner ) ;
if ( ! dragEl . contains ( el ) ) {
if ( after && ! nextSibling ) {
@ -848,6 +867,8 @@
_off ( ownerDocument , 'touchend' , this . _onDrop ) ;
_off ( ownerDocument , 'pointerup' , this . _onDrop ) ;
_off ( ownerDocument , 'touchcancel' , this . _onDrop ) ;
_off ( ownerDocument , 'pointercancel' , this . _onDrop ) ;
_off ( ownerDocument , 'selectstart' , this ) ;
} ,
_onDrop : function ( /**Event*/ evt ) {
@ -876,6 +897,11 @@
ghostEl && ghostEl . parentNode . removeChild ( ghostEl ) ;
if ( rootEl === parentEl || Sortable . active . lastPullMode !== 'clone' ) {
// Remove clone
cloneEl && cloneEl . parentNode . removeChild ( cloneEl ) ;
}
if ( dragEl ) {
if ( this . nativeDraggable ) {
_off ( dragEl , 'dragend' , this ) ;
@ -895,7 +921,6 @@
newIndex = _index ( dragEl , options . draggable ) ;
if ( newIndex >= 0 ) {
// Add event
_dispatchEvent ( null , parentEl , 'add' , dragEl , parentEl , rootEl , oldIndex , newIndex ) ;
@ -908,9 +933,6 @@
}
}
else {
// Remove clone
cloneEl && cloneEl . parentNode . removeChild ( cloneEl ) ;
if ( dragEl . nextSibling !== nextEl ) {
// Get the index of the dragged element within its parent
newIndex = _index ( dragEl , options . draggable ) ;
@ -965,19 +987,31 @@
putSortable =
activeGroup =
Sortable . active = null ;
savedInputChecked . forEach ( function ( el ) {
el . checked = true ;
} ) ;
savedInputChecked . length = 0 ;
} ,
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' ) {
if ( dragEl ) {
this . _onDragOver ( evt ) ;
_globalDragOver ( evt ) ;
}
}
else if ( type === 'drop' || type === 'dragend' ) {
this . _onDrop ( evt ) ;
case 'selectstart' :
evt . preventDefault ( ) ;
break ;
}
} ,
@ -1172,8 +1206,8 @@
el . classList [ state ? 'add' : 'remove' ] ( name ) ;
}
else {
var className = ( ' ' + el . className + ' ' ) . replace ( RSPACE , ' ' ) . replace ( ' ' + name + ' ' , ' ' ) ;
el . className = ( className + ( state ? ' ' + name : '' ) ) . replace ( RSPACE , ' ' ) ;
var className = ( ' ' + el . className + ' ' ) . replace ( R _ SPACE, ' ' ) . replace ( ' ' + name + ' ' , ' ' ) ;
el . className = ( className + ( state ? ' ' + name : '' ) ) . replace ( R _ SPACE, ' ' ) ;
}
}
}
@ -1247,7 +1281,7 @@
}
function _onMove ( fromEl , toEl , dragEl , dragRect , targetEl , targetRect , originalEvt ) {
function _onMove ( fromEl , toEl , dragEl , dragRect , targetEl , targetRect , originalEvt , willInsertAfter ) {
var evt ,
sortable = fromEl [ expando ] ,
onMoveFn = sortable . options . onMove ,
@ -1262,6 +1296,7 @@
evt . draggedRect = dragRect ;
evt . related = targetEl || toEl ;
evt . relatedRect = targetRect || toEl . getBoundingClientRect ( ) ;
evt . willInsertAfter = willInsertAfter ;
fromEl . dispatchEvent ( evt ) ;
@ -1290,10 +1325,8 @@
// 5 — min delta
// abs — нельзя добавлять, а то глюки при наведении сверху
return (
( evt . clientY - ( rect . top + rect . height ) > 5 ) ||
( evt . clientX - ( rect . right + rect . width ) > 5 )
) && lastEl ;
return ( evt . clientY - ( rect . top + rect . height ) > 5 ) ||
( evt . clientX - ( rect . left + rect . width ) > 5 ) ;
}
@ -1396,6 +1429,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
Sortable . utils = {
on : _on ,
@ -1425,6 +1486,6 @@
// Export
Sortable . version = '1.5.0-rc 1' ;
Sortable . version = '1.5.1' ;
return Sortable ;
} ) ;