You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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 .s with square (width * height) of element/container.
In sort function, if both elements .q are 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!
The text was updated successfully, but these errors were encountered:
if(!se.container&&// not the container element(se.element[0].scrollHeight||se.element[0].scrollWidth)){// element is visiblevarsePart=se.getPart();candidates.push({element: se.element,q: getDistance(mouse,seCoords),s: getSquare(rect),// <-- Squareview: sePart,targetIndex: se.getIndex(),after: shouldBeAfter(center,mouse,('isGrid'insePart) ? sePart.isGrid : isGrid)});}if(se.container&&!se.element[0].querySelector('[sv-element]:not(.sv-placeholder):not(.sv-source)')// empty container){varc=center;if(se.centerVariant==='vertical'){c=centerVert;}elseif(se.centerVariant==='horizontal'){c=centerHoriz;}candidates.push({element: se.element,q: (c.x-mouse.x)*(c.x-mouse.x)+(c.y-mouse.y)*(c.y-mouse.y),s: getSquare(rect),// <-- Squareview: se.getPart(),targetIndex: 0,container: true});}});varpRect=$placeholder[0].getBoundingClientRect();candidates.push({q: getDistance(mouse,getCoords(pRect)),s: getSquare(pRect),// <-- Square (no need it there, really)element: $placeholder,placeholder: true});candidates.sort(function(a,b){if(a.q==b.q)returna.s-b.s;// <-- Using the squaresreturna.q-b.q;});
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. ButgetDistance
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..s
with square (width * height) of element/container..q
are 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!
The text was updated successfully, but these errors were encountered: