How to detect dropping of element (ondragend event)?

813 views
Skip to first unread message

frank...@gmail.com

unread,
Jul 31, 2013, 12:20:35 PM7/31/13
to joi...@googlegroups.com
Hi  I want to detect when one element is dragged around and dropped on another element.

In plain JavaScript I would react to the ondragend event.  But how do I do this with JointJS v.0.6.
I can see no drag-events there.

All I can see are the "cell:pointerup" and "cell:pointer-down  events on the paper.
Thus I added the following two  handler to my code:

   this.paper.on( "cell:pointerdown", function( cellview, evt, x, y)  {
        console.log( "pointer down on cell ", cellview.model.id, " pos: ", x , ",", y);
    });

    this.paper.on( "cell:pointerup", function( cellview, evt, x, y)  {
        console.log( "pointer up on cell ", cellview.model.id, " pos: ", x , ",", y);
        
    });
   
The ein started to drag around elements.

I learned that as cellview  I always get the one for the element I dragged around.
Thus my plan was to in the pointerup method take the mouse position and then find the object(s) at this position and then fint out what element I dropped onto.
 
However I found, that the mouse coordinates are undefined.

pointer down on cell 50a9e6b6-9e98-4ba7-8b7a-70dfdccf7094 pos: 60 , 25 VsfGraph.js:353
pointer up on cell 50a9e6b6-9e98-4ba7-8b7a-70dfdccf7094 pos: undefined , undefined VsfGraph.js:357
pointer down on cell 50a9e6b6-9e98-4ba7-8b7a-70dfdccf7094 pos: 205 , 320 VsfGraph.js:353
pointer up on cell 50a9e6b6-9e98-4ba7-8b7a-70dfdccf7094 pos: undefined , undefined 

Is there a way to find out where or on what element I dropped something?
Or can how can I define an handler for the ondragend or onmouseenter events?

frank...@gmail.com

unread,
Jul 31, 2013, 12:31:45 PM7/31/13
to joi...@googlegroups.com
Okay I found there is also the  cell-pointermove event, which will report the mouse position.
Thus I can take the position from the last pointermove event.

However I would prefer to get the mouse position in the pointerup directly.

dave

unread,
Aug 5, 2013, 6:29:28 AM8/5/13
to joi...@googlegroups.com
done in v0.6.1. cell:pointerup event contains x,y coordinates as well.
Reply all
Reply to author
Forward
0 new messages