-
Notifications
You must be signed in to change notification settings - Fork 142
Description
I have a list of elements. Some elements may have children elements. And so on. Basically, I have a tree. :)
I show this tree as nested lists, and I want user to be able to rearrange items in one dimension (before-after) and move elements freely between any levels of sub-lists.
Physically I render list as recursive component: if element have sub-list, the same component is called. All components have the same sv-root value.
The problem I stumbled upon was that sv always choose element from root list as target. The reason is this part of code:
https://github.com/kamilkp/angular-sortable-view/blob/master/src/angular-sortable-view.js#L196-L255
getDistance is used to store distance to elements. But getDistance returns 0 if mouse is inside element. So the first element from several nested elements is selected as best candidate and this first element is always from the root list.
- I added field
.swith square (width * height) of element/container. - In sort function, if both elements
.qare equal, I sort them using their squares.
This way smallest (innermost!) element is placed first among candidates. Exactly what was needed! Hope this helps someone :)
And many thanks to @kamilkp for such great module!