From da7e33879c1e25e7879f82afc3f22630435c976b Mon Sep 17 00:00:00 2001 From: Mostafa Barmshory Date: Fri, 3 Aug 2018 21:28:42 +0430 Subject: [PATCH] Find the best position of place holder where event target is the list itself Suppose all children of a dnd-list have margin and you are about to insert a new item between them. In this case, the event target and the list are the same and the placeholder will be put at the end of the list. In this commit, a correct location for both placeholder and the new element is computed based on the dnd-list itself. --- angular-drag-and-drop-lists.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/angular-drag-and-drop-lists.js b/angular-drag-and-drop-lists.js index 8a07ce3..9c917a4 100644 --- a/angular-drag-and-drop-lists.js +++ b/angular-drag-and-drop-lists.js @@ -339,6 +339,26 @@ listNode.insertBefore(placeholderNode, isFirstHalf ? listItemNode : listItemNode.nextSibling); } + } else { + var listItemNode = null; + for(var i = 0; i < listNode.childNodes.length; i++){ + var node = listNode.childNodes[i]; + var rect = node.getBoundingClientRect(); + if (listSettings.horizontal) { + if(rect.left > event.clientX) { + listItemNode = node; + break; + } + } else { + if(rect.top > event.clientY) { + listItemNode = node; + break; + } + } + } + if(node){ + listNode.insertBefore(placeholderNode, node); + } } // In IE we set a fake effectAllowed in dragstart to get the correct cursor, we therefore