Browse Source

+ _revertDragElement

drag-over-refactoring
Lebedev Konstantin 8 years ago
parent
commit
047c40045c
  1. 43
      Sortable.js

43
Sortable.js

@ -686,14 +686,15 @@
!options.dragoverBubble && evt.stopPropagation(); !options.dragoverBubble && evt.stopPropagation();
} }
if (dragEl.animated) { // Smart auto-scrolling
return; _autoScroll(evt, options, this.el);
}
moved = true; moved = true;
// Check base state // Check base state
if ( if (
_silent ||
dragEl.animated ||
!activeSortable || !activeSortable ||
options.disabled || options.disabled ||
!(evt.rootEl === void 0 || evt.rootEl === this.el) // touch fallback !(evt.rootEl === void 0 || evt.rootEl === this.el) // touch fallback
@ -719,38 +720,18 @@
} }
} }
target = _closest(evt.target, options.draggable, el);
dragRect = dragEl.getBoundingClientRect();
if (putSortable !== this) { if (putSortable !== this) {
putSortable = this; putSortable = this;
isMovingBetweenSortable = true; isMovingBetweenSortable = true;
} }
// Smart auto-scrolling if (revert) {
_autoScroll(evt, options, this.el); _revertDragElement(activeSortable, canSort);
if (_silent) {
return; return;
} }
target = _closest(evt.target, options.draggable, el); target = _closest(evt.target, options.draggable, el);
dragRect = dragEl.getBoundingClientRect(); dragRect = dragEl.getBoundingClientRect();
putSortable = this;
if (revert) {
_cloneHide(activeSortable, true);
parentEl = rootEl; // actualization
if (cloneEl || nextEl) {
rootEl.insertBefore(dragEl, cloneEl || nextEl);
}
else if (!canSort) {
rootEl.appendChild(dragEl);
}
return;
}
if ((el.children.length === 0) || (el.children[0] === ghostEl) || if ((el.children.length === 0) || (el.children[0] === ghostEl) ||
(el === evt.target) && (target = _ghostIsLast(el, evt)) (el === evt.target) && (target = _ghostIsLast(el, evt))
@ -1321,6 +1302,18 @@
} }
function _revertDragElement(activeSortable, canSort) {
_cloneHide(activeSortable, true);
parentEl = rootEl; // actualization
if (cloneEl || nextEl) {
rootEl.insertBefore(dragEl, cloneEl || nextEl);
} else if (!canSort) {
rootEl.appendChild(dragEl);
}
}
/** @returns {HTMLElement|false} */ /** @returns {HTMLElement|false} */
function _ghostIsLast(el, evt) { function _ghostIsLast(el, evt) {
var lastEl = el.lastElementChild, var lastEl = el.lastElementChild,

Loading…
Cancel
Save