0

I am using the shapeshift plugin in order to create a user interface that allows for certain images to be dropped from a container into another. The child container allows images to be dropped into it from a parent container. When the images are being dragged from the parent container to the child container i want to create a duplicate (dragClone set to true) in the parent container because I do not want to lose the information on this container. This way I can drag the same image from the parent container to the child container multiple times and generate copies.

However, my issue is that these images have a hover listener attached to them. I do not want to lose the hover listener when the shapeshift clone is created. Therefore, I analyzed the shapeshift code and found this:

if (drag_clone) {
    $clone = $selected.clone(false, false).insertBefore($selected).addClass(clone_class);
}

And changed it to the following:

if (drag_clone) {
    //changed clone type to add data and events
    $clone = $selected.clone(true, false).insertBefore($selected).addClass(clone_class);
}

This works fine, as the clone is created and the hover listener works both on the clone (which is kept on the parent container) and the original element (which is moved to the child container).

However, the issue that I am finding now, is that I am unable to generate a new clone. After the image is dragged for the first time, if I try to drag the same image again from the parent to the child container, the previously dragged image (which is was previously dragged to the child container) disappears.

Is this some issue with jquery's clone functionality? Thanks!

EDIT I guess I know what the issue might be. When dragging to the child container, we are actually moving the original element. This causes, that when the cloned element is selected once again, the original element is replaced by it. I have also added delete funcitonality and when deleting from the child container I am not able to drag the same element at all. I guess it is just a matter of dragging the clone instead of the original element...

Magicprog.fr
  • 4,072
  • 4
  • 26
  • 35
luisgepeto
  • 763
  • 1
  • 11
  • 36
  • Is that only an issue *after* you've changed that `false` to `true` to retain the event handler(s)? Or is it also an issue when not retaining them? – Anthony Grist Jul 11 '15 at 08:49
  • Yes this is an issue only after I changed the clone parameters to true. – luisgepeto Jul 11 '15 at 08:58
  • Try using event delegation for your `hover` handler instead of cloning with events. (That might need rewriting your handler to `.on`, if your are using `.hover` right now.) – CBroe Jul 11 '15 at 09:13

0 Answers0