From 0bd46593ff60aa0b923e441cf37ddb9ca9f024f9 Mon Sep 17 00:00:00 2001 From: Lebedev Konstantin Date: Thu, 16 Feb 2017 19:55:00 +0300 Subject: [PATCH] #1017: + revertClone --- Sortable.js | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/Sortable.js b/Sortable.js index b93a513..18966b9 100644 --- a/Sortable.js +++ b/Sortable.js @@ -210,6 +210,7 @@ group.name = originalGroup.name; group.checkPull = toFn(originalGroup.pull, true); group.checkPut = toFn(originalGroup.put); + group.revertClone = originalGroup.revertClone; options.group = group; } @@ -709,7 +710,7 @@ putSortable = this; if (revert) { - _cloneHide(true); + _cloneHide(activeSortable, true); parentEl = rootEl; // actualization if (cloneEl || nextEl) { @@ -734,7 +735,7 @@ targetRect = target.getBoundingClientRect(); } - _cloneHide(isOwner); + _cloneHide(activeSortable, isOwner); if (_onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt) !== false) { if (!dragEl.contains(el)) { @@ -771,7 +772,7 @@ _silent = true; setTimeout(_unsilent, 30); - _cloneHide(isOwner); + _cloneHide(activeSortable, isOwner); if (moveVector === 1 || moveVector === -1) { after = (moveVector === 1); @@ -815,6 +816,10 @@ if (ms) { var currentRect = target.getBoundingClientRect(); + if (prevRect.nodeType === 1) { + prevRect = prevRect.getBoundingClientRect(); + } + _css(target, 'transition', 'none'); _css(target, 'transform', 'translate3d(' + (prevRect.left - currentRect.left) + 'px,' @@ -1094,10 +1099,21 @@ }; - function _cloneHide(state) { + function _cloneHide(sortable, state) { if (cloneEl && (cloneEl.state !== state)) { _css(cloneEl, 'display', state ? 'none' : ''); - !state && cloneEl.state && rootEl.insertBefore(cloneEl, dragEl); + + if (!state) { + if (cloneEl.state) { + if (sortable.options.group.revertClone) { + rootEl.insertBefore(cloneEl, nextEl); + sortable._animate(dragEl, cloneEl); + } else { + rootEl.insertBefore(cloneEl, dragEl); + } + } + } + cloneEl.state = state; } } @@ -1374,7 +1390,6 @@ ); } - // Export utils Sortable.utils = { on: _on,