draggable icon indicating copy to clipboard operation
draggable copied to clipboard

Question: Motivation for cloning "originalSource"

Open stkao05 opened this issue 7 years ago β€’ 6 comments

When an element gets dragged, a clone of the element is created and also the original element will get hidden. Just curious about the motivation for such a behavior πŸ™‚

(For my specific use case... this behavior a bit undesirable, but not really a major issue)

stkao05 avatar Jun 27 '18 05:06 stkao05

@stkao05 what is the exact behaviour that you need?

As of the latest pushes to master, we have made it so the mirror has been abstracted a bit more. You can now initialize draggable without any mirror.

As for cloning behaviour - the reason why we have a source vs originalSource is because of what happens with touch events. Since draggable items are being moved around in the DOM as you drag, that means the original element that you have initiated the event on has been changed in some way (example: removed and reappended to the dom). This just won't fly sadly - so:

  • on drag:start, hide the originalSource and leave it in place in the DOM
  • duplicate the originalSource as source and append it next to originalSource
  • now start moving this new source around in the DOM
    • changes happen to source while originalSource can retain the original eventListener
  • on drag:stop, remove the cloned source and replace it with the originalSource

Does that make sense? Please let me know if you need more clarity.

@tsov in case you have a better description.

beefchimi avatar Jun 27 '18 13:06 beefchimi

Thanks for the detail explanation @beefchimi πŸ™‚Glad to see the library is still in active development.

Sorry, I am still trying to wrap my head around it. Yes, the original draggable item could be changed in some way during the drag-and-drop process, but I wasn't sure why would that be an issue?

stkao05 avatar Jun 28 '18 07:06 stkao05

^ @tsov was there anything you wanted to add here?

beefchimi avatar Jul 19 '18 13:07 beefchimi

@beefchimi you got it πŸ‘

We should really file an issue about this, this always sounded like a browser bug to me!

tsov avatar Jul 29 '18 17:07 tsov

Would there be a side-effect to removing the style attributes which hides the original? The reason I want it is that I want to display the original until I drop the element to its new position. Or is there a more idiomatic way of achieving this?

seanogdev avatar Jan 08 '21 02:01 seanogdev

Would there be a side-effect to removing the style attributes which hides the original? The reason I want it is that I want to display the original until I drop the element to its new position. Or is there a more idiomatic way of achieving this?

Hi @miralize , If removing the display: none of the originalSource, it will also act as a draggable element and move over it will trigger drag:over. It seems that clone an originalSource again and remove the draggable class of it can avoid treating it as a draggable element.

zjffun avatar Jan 09 '21 12:01 zjffun