jumping endpoints with nested element dragging

670 views
Skip to first unread message

Gregor Raschke

unread,
Aug 6, 2013, 9:57:04 AM8/6/13
to jsp...@googlegroups.com
Hi all,

this is my first post in this group, so please be gentle ;-)

In my application I have modeled some pages (as div-container), that have nodes (div-container as well) in them. 
Those nodes can be connected to every other node on the same page, or on other pages. Every page and every node
is draggable (pages can be moved freely, nodes are contained in there page).

The problem occurs when I drag a page, that is some endpoints are jumping while I move the page. When I let go, the
endpoint snaps back to place. If I drag a single node everything is fine.

I made a very simple fiddle, which can be found here: http://jsfiddle.net/WcmEL/1/

I already tried repainting everything on dragging-progress-event, but that does not help.


Any suggestions on what I can do to fix this?

Gregor Raschke

unread,
Aug 6, 2013, 10:28:57 AM8/6/13
to jsp...@googlegroups.com
A small addition:

while playing with the fiddle I realized another strange behaviour:
When I drag the nodes multiple times from place to place, the connections move away from the endpoints, too (see screenshot).

I'm a big fan of jsPlumb and hope that those mishaps can be easily resolved.



Simon Porritt

unread,
Aug 6, 2013, 11:35:31 AM8/6/13
to jsp...@googlegroups.com
You have actually hit a bug in the current version of jsPlumb, which is fixed in 1.5.0.  As it happens I spent some time this afternoon finalising the 1.5.0 release and I have a dry run of it on my server; this fiddle points to it:


when you drag the `.page` divs, the `.node` divs track correctly.  however, when you drag a node div and then subsequently drag its parent, the connection does not update.

This is due to the situation explained in the 'Nested Elements Offsets' section of this page:


...and so can be remedied by making a call to `jsPlumb.recalculateOffsets` in the drag stop callback for the `.node` elements, as in this fiddle:




Gregor Raschke

unread,
Aug 6, 2013, 11:47:23 AM8/6/13
to jsp...@googlegroups.com
Hi,

that was fast. Cool, so when is 1.5.0 coming out, or do I steal it from the fiddle? ;-)

Best regards and keep up the good work


2013/8/6 Simon Porritt <simon....@gmail.com>

--
You received this message because you are subscribed to a topic in the Google Groups "jsPlumb" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jsplumb/IoOW2tw5IXY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jsplumb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Simon Porritt

unread,
Aug 6, 2013, 11:50:35 AM8/6/13
to jsp...@googlegroups.com
i'm in that final phase where everything seems to be squared away but i have this niggling feeling like i've forgotten something!  soon.  hopefully tomorrow.  by all means yoink it from the fiddle if you want - it's on the dev/1.5.0 branch on GitHub right now anyway; it's not super-secret.  and if anything changes it won't be anything significant.

Simon Porritt

unread,
Aug 6, 2013, 12:07:35 PM8/6/13
to jsp...@googlegroups.com
...btw i don't know if you noticed, but in that second fiddle i consolidated your drag selectors down, eg:

jsPlumb.draggable($(".page"))

instead of having to do each one by its id.

Gregor Raschke

unread,
Aug 6, 2013, 12:37:16 PM8/6/13
to jsp...@googlegroups.com
I didn't notice, but in my real Application each node is inserted one at a time, so I guess that wouldn't really help me.

Not sure, if I should open a new thread, but I have another question:

In my application, those pages can be minimized and in the minified state the nodes become list-items.
My question: how would I reconnect the list-items with nodes of other pages? Would I delete old connections and 
endpoints and create new ones, or is it possible to move endpoints from one html-object to another?


2013/8/6 Simon Porritt <simon....@gmail.com>
...btw i don't know if you noticed, but in that second fiddle i consolidated your drag selectors down, eg:

jsPlumb.draggable($(".page"))

instead of having to do each one by its id.

--

Simon Porritt

unread,
Aug 6, 2013, 2:05:58 PM8/6/13
to jsp...@googlegroups.com
There is a 'setElement' method on Endpoint which changes the element the Endpoint is assigned to:


this should do what you need, i think.

Gregor Raschke

unread,
Aug 7, 2013, 4:29:05 AM8/7/13
to jsp...@googlegroups.com
It's me again,

I tried the setElement-method, but got an error of  'Uncaught TypeError: Object [object Object] has no method 'getAttribute'
I couldn't debug it, because the 1.5.0 is 'too large' for my debugger^^

I build a fiddle that roughly reproduces the issue: http://jsfiddle.net/tyregor/exbZP/1/

Hope this is only a small bump on the road...

Simon Porritt

unread,
Aug 7, 2013, 4:30:57 AM8/7/13
to jsp...@googlegroups.com
1.5.0 is too large for your debugger!  are you on a 286???

you need to pass it a DOM element for now. not a selector.  i will change the code before the 1.5.0 release to support a selector aswell.

Gregor Raschke

unread,
Aug 7, 2013, 4:41:09 AM8/7/13
to jsp...@googlegroups.com
Maybe it's a 286, I never tell.

Ok changed it to

ep1.setElement( $('#row-node1').get(0), true ) (see http://jsfiddle.net/tyregor/exbZP/2/)

and the result is now: Uncaught TypeError: Cannot call method 'createDocumentFragment' of undefined


Simon Porritt

unread,
Aug 7, 2013, 5:06:32 AM8/7/13
to jsp...@googlegroups.com
the second argument to that function is not a boolean; it's an optional DOM element that lets you specify a custom 'container' for it (so you'd never really use it).

having said that, in this fiddle it doesn't position properly:


(you have to click the .page element to get it to swap)

Gregor Raschke

unread,
Aug 7, 2013, 5:11:23 AM8/7/13
to jsp...@googlegroups.com
That was embarrassing. Thanks for the info

Simon Porritt

unread,
Aug 7, 2013, 5:15:53 AM8/7/13
to jsp...@googlegroups.com
no problem...i am of course looking at this.  but i'm heading out now so i wont get back to it until a little later.

Gregor Raschke

unread,
Aug 7, 2013, 6:17:39 AM8/7/13
to jsp...@googlegroups.com
So I played a little more with the whole 'setElement' thing and encountered another issue.

Please have a look at this fiddle: http://jsfiddle.net/tyregor/Ac4GJ/1/

If you click on the node on the left, the endpoint is moved to the list item on the right. So far so good.
I actually also change the anchor of that endpoint too, which seems to be ignored.
If I now drag the node on the left a little, the endpoint reappears on that node with the changed anchor...

Gregor Raschke

unread,
Aug 7, 2013, 10:57:48 AM8/7/13
to jsp...@googlegroups.com
Automagically fixed^^

Always link your fiddles to the server-version of the author...

Gregor Raschke

unread,
Aug 7, 2013, 11:16:34 AM8/7/13
to jsp...@googlegroups.com
I hope I don't annoy you to much by now, but I still have some issues.

I made the list-container now draggable (see http://jsfiddle.net/tyregor/Ac4GJ/3/) and if I drag it after I changed the endpoints, one moves along and one stays in place.

Simon Porritt

unread,
Aug 7, 2013, 11:37:48 AM8/7/13
to jsp...@googlegroups.com
ha ha, yeah.  but it's not 100% there yet: you can't drag from the endpoint after it has moved. this is due to the fact that the element is removed from the DOM and then re-added. but in fact since the parent it hangs off doesn't actually change, that doesn't need to happen. so for 1.5.0 i am temporarily removing the 'container' argument, and i'll see about putting it back in in a later version.  i'll update this thread again once i've made the other couple of outstanding changes.

Simon Porritt

unread,
Aug 7, 2013, 11:38:35 AM8/7/13
to jsp...@googlegroups.com
oh i just saw your other email. right. it's not fixed yet.  i will update this when it is fixed.

Simon Porritt

unread,
Aug 10, 2013, 12:45:08 PM8/10/13
to jsp...@googlegroups.com
Here's the latest:


In this fiddle I've added another element, that has a source/target endpoint on it.  This for testing the setElement method properly - when it switches it should of course take all of its connections with it.  So you can try dragging from node 3 to node 1 and then clicking on node 1, and also dragging from node 1 to node 3 and then clicking on node 1.  both cases should work.

let me know how you go.

Gregor Raschke

unread,
Aug 11, 2013, 9:07:13 AM8/11/13
to jsp...@googlegroups.com
The fiddle looks promising. I will test it tomorrow with my actual code and get back at you.

Gregor Raschke

unread,
Aug 12, 2013, 9:34:17 AM8/12/13
to jsp...@googlegroups.com
So I integrated the current version and what can I say other then: Thanks you very much. Works like a charm

Simon Porritt

unread,
Aug 12, 2013, 9:38:33 AM8/12/13
to jsp...@googlegroups.com
Excellent!  Thanks for getting back to me about it.
Reply all
Reply to author
Forward
0 new messages