Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect non-element node original positions when reverting on cancel #551

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions dragula.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function dragula (initialContainers, options) {
var _offsetY; // reference y
var _moveX; // reference move x
var _moveY; // reference move y
var _initialSiblingNode; // reference sibling node when grabbed
var _initialSibling; // reference sibling when grabbed
var _currentSibling; // reference sibling now
var _copy; // item used for copying
Expand Down Expand Up @@ -206,6 +207,7 @@ function dragula (initialContainers, options) {

_source = context.source;
_item = context.item;
_initialSiblingNode = context.item.nextSibling;
_initialSibling = _currentSibling = nextEl(context.item);

drake.dragging = true;
Expand Down Expand Up @@ -284,14 +286,10 @@ function dragula (initialContainers, options) {
var item = _copy || _item;
var parent = getParent(item);
var initial = isInitialPlacement(parent);
if (initial === false && reverts) {
if (_copy) {
if (parent) {
parent.removeChild(_copy);
}
} else {
_source.insertBefore(item, _initialSibling);
}
if (initial === false && reverts && _copy && parent) {
parent.removeChild(_copy);
} else if (reverts && !_copy) {
_source.insertBefore(item, _initialSiblingNode);
}
if (initial || reverts) {
drake.emit('cancel', item, _source, _source);
Expand All @@ -316,7 +314,7 @@ function dragula (initialContainers, options) {
drake.emit('out', item, _lastDropTarget, _source);
}
drake.emit('dragend', item);
_source = _item = _copy = _initialSibling = _currentSibling = _renderTimer = _lastDropTarget = null;
_source = _item = _copy = _initialSiblingNode = _initialSibling = _currentSibling = _renderTimer = _lastDropTarget = null;
}

function isInitialPlacement (target, s) {
Expand Down