luckylooke / dragular

Angular drag and drop based on dragula.js. Visit
http://luckylooke.github.io/dragular/
MIT License
209 stars 67 forks source link

Get the source ID of dragged element #172

Closed abtx closed 6 years ago

abtx commented 6 years ago

I've created a tree with Dragular, which now I want to use so that when I drag an element over a node I can drop it on that node as a child element. I tried to look for properties when using dragularleave and dragulardrop: I use a unique ID for each node with e.target.getAttribute('id') so I know what I'm hovering over. Now I need to know what is the unique ID of the actual element I drag so that I don't trigger a function that will expand child elements of a node on the dragged node. Right now when I move an element, the first 'target' is the very same node I drag, so I need to find a way to eliminate it as a real target on hover over. If I had the source ID I can say something like don't fire expandChildNodes() if the target has the same ID as the source. Is there a way to access the source's ID attribute like that? Thanks!

luckylooke commented 6 years ago

Sure.. there is always a way :) In dragularenter event listener, access dragularService.shared.source. It is an container element where the item was dragged from, you can also check dragularService.shared.target

All the properties of the shared object are commented in source at the top of the file: https://github.com/luckylooke/dragular/blob/master/src/dragularService.js

You may find useful other properties too.. I did not documented it because I wanted to handle it another way, but since I have stopped the development of this library for now, it is hardly to be changed in foreseeable future.

abtx commented 6 years ago

Thanks @luckylooke, dragularService.shared.source returns the container though, but sourceItem does the trick! Excellent, thanks for a quick reply!!