提交 77e04818 编写于 作者: O Owen Mills

#1942: Check if ghost is first

上级 a12fb2bc
......@@ -1175,7 +1175,7 @@ Sortable.prototype = /** @lends Sortable.prototype */ {
return completed(false);
}
// assign target only if condition is true
// if there is a last element, it is the target
if (elLastChild && el === evt.target) {
target = elLastChild;
}
......@@ -1193,6 +1193,23 @@ Sortable.prototype = /** @lends Sortable.prototype */ {
return completed(true);
}
}
else if (elLastChild && _ghostIsFirst(evt, vertical, this)) {
let firstChild = getChild(el, 0, options, true);
if (firstChild === dragEl) {
return completed(false);
}
target = firstChild;
targetRect = getRect(target);
if (onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt, false) !== false) {
capture();
el.insertBefore(dragEl, firstChild);
parentEl = el; // actualization
changed();
return completed(true);
}
}
else if (target.parentNode === el) {
targetRect = getRect(target);
let direction = 0,
......@@ -1762,6 +1779,14 @@ function _unsilent() {
_silent = false;
}
function _ghostIsFirst(evt, vertical, sortable) {
let rect = getRect(getChild(sortable.el, 0, sortable.options));
const spacer = 10;
return vertical ?
((evt.clientX < rect.left - spacer) || (evt.clientY < rect.top && evt.clientX < rect.right)) :
((evt.clientY < rect.top - spacer) || (evt.clientY < rect.bottom && evt.clientX < rect.left))
}
function _ghostIsLast(evt, vertical, sortable) {
let rect = getRect(lastChild(sortable.el, sortable.options.draggable));
......
......@@ -296,7 +296,7 @@ function isScrolledPast(el, elSide, parentSide) {
* @param {Object} options Parent Sortable's options
* @return {HTMLElement} The child at index childNum, or null if not found
*/
function getChild(el, childNum, options) {
function getChild(el, childNum, options, includeDragEl) {
let currentChild = 0,
i = 0,
children = el.children;
......@@ -305,7 +305,7 @@ function getChild(el, childNum, options) {
if (
children[i].style.display !== 'none' &&
children[i] !== Sortable.ghost &&
children[i] !== Sortable.dragged &&
(includeDragEl || children[i] !== Sortable.dragged) &&
closest(children[i], options.draggable, el, false)
) {
if (currentChild === childNum) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册