Oh, my code only demonstrates the idea of restricting the dragging. There is no collision test at all, it is just like this – if the object is too far from the center, stop dragging it. For your case you have to use collision test.
I will see your second pen later on.
Edit: Looked at the pen. Got confused. Decided to make a new example with two cubes. Any of them can be dragged, but it will stop when collides with the other.
https://codepen.io/boytchev/full/oNVoQwE
As I spent too much time on this, I hope you can manage to complete your project.