I'm making a jQuery UI sortable and I need to detect when an element is dragged out of it. Sounds EXACTLY like a job for the out event - except for one tiny remark that I myself missed initially:
Note: This event is also triggered when a sortable item is dropped.
This is a major showstopper for me. Whenever the items are merely rearranged, the dragged item still gets an out
event in the end. I've been racking my brain but so far to no awail. How do I detect if an out
event is because the item was really dragged outside, or wheter it's just because the drag operation is stopping?
(If it matters, jQuery UI version 1.11.4)
Added:
OK, I think I myself fell victim to the "just the last nonsensical part left" trap. What I was trying to do was to have two sortables that can have items dragged between them. Like the example, but with the placeholder disappearing completely when the item is dragged outside all sortables. Which is why I wanted to keep track of which items are inside and which items are outside.
The way I solved it in the end was to drop this "requirement". It's better anyway if the placeholder stays, because it shows where the item will get dropped to when the mouse is released - even when it is outside.
If I did want to keep to this path however, I now see that the correct solution would be to hide the placeholder on an out
event, and show it on an over
event. There's an over
even when the dragging starts, although no item is being dragged in from the outside.
Either way, although both approaches would solve my real problem, neither of them really answer the question that I asked, so I'll let it stay.