I'm creating a user interface that allows users to create database tables (and their fields and relationships) via drag/drop interface.
Here is the jsFiddle I created, and although it looks like it has a lot going on, it's actually just the bare minimum necessary to demonstrate the problem. Here are my requirements, which jsPlumb handles beautifully separately, but I run into problems when I try to do them all together. In particular, it's combining #2 and #3 that are an issue.
To accomplish #4, I call jsPlumb.makeSource() and jsPlumb.makeTarget() on each "tile" that represents a field, rather than creating specific endpoints on the right and left side of each tile. That way jsPlumb can manage the redrawing of the connecting lines to whichever side of the "field" tile that is closer to the tile its connected to.
However, to accomplish #2 I'm applying jQuery sortable to the fields to give the user the "drag to re-order" feature. This creates a conflict as to which "action" you're requesting when you click on a field...sorting or initiating a jsPlumb connection? So to each field I append a red div (with a class of ".item-hit.area") and I add a filter to the makeSource() call so that only that red div can be used to create a new jsPlumb connection.
jsPlumb.makeSource($('.item'), {
filter:function(event, element) {
return ($(event.target).hasClass('item_hit_area'));
}
....
}
So now clicking on the red div tells jsPlumb to initiate a connection, or clicking anywhere else within a "field" element is passed through to jQuery sortable().
Hopefully those requirements are clear. Here is how to recreate the problem.
Stranger still is that if you drag the other table (the "All my Bars" table), the connecting line jumps back to the correct position on both ends. It's only when you drag the table that was on the "source" side of the jsPlumb connection that it gets confused and draws the line in the wrong place.
The problem is that jsPlumb caches the offsets of child elements of some draggable. So after you sort you need to tell jsPlumb to recalculate those offsets, as in this fiddle:
notice the line:
jsPlumb.recalculateOffsets($(ui.item).parents(".draggable"));
in the sortable's stop callback.